Skip to content

Commit 2b07ff3

Browse files
Peter Stugegitster
authored andcommitted
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 <[email protected]> Acked-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a86dd5 commit 2b07ff3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

gitweb/static/js/javascript-detection.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* and other reasons to not add 'js=1' param at the end of link
1717
* @constant
1818
*/
19-
var jsExceptionsRe = /[;?]js=[01]$/;
19+
var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
2020

2121
/**
2222
* Add '?js=1' or ';js=1' to the end of every link in the document
@@ -33,9 +33,9 @@ function fixLinks() {
3333
var allLinks = document.getElementsByTagName("a") || document.links;
3434
for (var i = 0, len = allLinks.length; i < len; i++) {
3535
var link = allLinks[i];
36-
if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/;
37-
link.href +=
38-
(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
36+
if (!jsExceptionsRe.test(link)) {
37+
link.href = link.href.replace(/(#|$)/,
38+
(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
3939
}
4040
}
4141
}

0 commit comments

Comments
 (0)