From: Peter Stuge <peter@stuge.se>
To: git@vger.kernel.org
Subject: [PATCH] gitweb: Fix links to lines in blobs when javascript-actions are enabled
Date: Tue, 27 Sep 2011 11:51:00 +0200 [thread overview]
Message-ID: <1317117060-3955-1-git-send-email-peter@stuge.se> (raw)
In-Reply-To: <20110927094947.10955.qmail@stuge.se>
Some javascript code will run in the browser onLoad and signals back to
gitweb that the browser can actually do javascript.
The code adds [?;]js=1 into the URL of all links on the page. The code
always added [?;]js=1 to the end of links, which is wrong when links
contain a URI fragment, such as links directly to a line in a blob:
..?p=repo.git;a=blob;f=file#l123
In this case, [?;]js=1 must be added before the hashmark.
Signed-off-by: Peter Stuge <peter@stuge.se>
---
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..fa2596f 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)) {
+ link.href = link.href.replace(/(#|$)/,
+ (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
}
}
}
--
1.7.4.1.343.ga91df.dirty
next prev parent reply other threads:[~2011-09-27 9:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-26 18:10 [PATCH] gitweb: Add js=1 before an URI fragment to fix line number links Peter Stuge
2011-09-26 19:27 ` Junio C Hamano
2011-09-26 19:46 ` Peter Stuge
2011-09-26 21:14 ` Junio C Hamano
2011-09-26 22:28 ` Peter Stuge
2011-09-27 6:44 ` Johannes Sixt
2011-09-27 9:49 ` Peter Stuge
2011-09-27 9:51 ` Peter Stuge [this message]
2011-09-27 17:17 ` [PATCH] gitweb: Fix links to lines in blobs when javascript-actions are enabled Junio C Hamano
2011-09-28 1:31 ` Peter Stuge
2011-09-27 17:40 ` [PATCH] gitweb: Add js=1 before an URI fragment to fix line number links Junio C Hamano
2011-09-26 23:06 ` Junio C Hamano
2011-09-26 23:17 ` Peter Stuge
2011-09-26 23:19 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1317117060-3955-1-git-send-email-peter@stuge.se \
--to=peter@stuge.se \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).