From: Peter Stuge Date: Tue, 27 Sep 2011 09:51:00 +0000 (+0200) Subject: gitweb: Fix links to lines in blobs when javascript-actions are enabled X-Git-Url: https://git.ladys.computer/Gitweb/commitdiff_plain/33d52e106c3bfe2109dcabef0dcad15ffa46da8f024dc12a51af9e1e59821313?hp=6317f81da0e9724817a39531276527bbe33a2aa68a051fbabaa8ef209f8c8384 gitweb: Fix links to lines in blobs when javascript-actions are enabled The fixLinks() function adds 'js=1' to each link that does not already have 'js' query parameter specified. This is used to signal to gitweb that the browser can actually do javascript when these links are used. There are two problems with the existing code: 1. URIs with fragment and 'js' query parameter, like e.g. ...foo?js=0#l199 were not recognized as having 'js' query parameter already. 2. The 'js' query parameter, in the form of either '?js=1' or ';js=1' was appended at the end of URI, even if it included a fragment (had a hash part). This lead to the incorrect links like this ...foo#l199?js=1 instead of adding query parameter as last part of query, but before the fragment part, i.e. ...foo?js=1#l199 Signed-off-by: Peter Stuge Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- diff --git a/static/js/javascript-detection.js b/static/js/javascript-detection.js index a06815a..228b25b 100644 --- a/static/js/javascript-detection.js +++ b/static/js/javascript-detection.js @@ -16,7 +16,7 @@ * and other reasons to not add 'js=1' param at the end of link * @constant */ -var jsExceptionsRe = /[;?]js=[01]$/; +var jsExceptionsRe = /[;?]js=[01](#.*)?$/; /** * Add '?js=1' or ';js=1' to the end of every link in the document @@ -33,9 +33,9 @@ function fixLinks() { var allLinks = document.getElementsByTagName("a") || document.links; for (var i = 0, len = allLinks.length; i < len; i++) { var link = allLinks[i]; - if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/; - link.href += - (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1'; + if (!jsExceptionsRe.test(link)) { + link.href = link.href.replace(/(#|$)/, + (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1'); } } }