From: Junio C Hamano Date: Mon, 26 Sep 2011 19:27:43 GMT Subject: Re: [PATCH] gitweb: Add js=1 before an URI fragment to fix line number links Message-ID: <7v62kf2jf4.fsf@alter.siamese.dyndns.org> In-Reply-To: <1317060642-25488-1-git-send-email-peter@stuge.se> Peter Stuge writes: > Signed-off-by: Peter Stuge > --- Care to elaborate a bit more please? Explanation of what you are fixing is totally lacking. What happens with the current code, why it is wrong, and how the updated pattern improves the result in what way? > gitweb/static/js/javascript-detection.js | 8 ++++---- > 1 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js > index 93dd2bd..003acd1 100644 > --- a/gitweb/static/js/javascript-detection.js > +++ b/gitweb/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)) { // =~ /[;?]js=[01](#.*)?$/; > + link.href = link.href.replace(/(#|$)/, > + (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1'); > } > } > }