Re: [PATCH] gitweb: Add js=1 before an URI fragment to fix line number links
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:07
Peter Stuge [off-list ref] writes:
Signed-off-by: Peter Stuge <redacted> ---
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?
quoted hunk
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'); } } }