From: Junio C Hamano <gitster@pobox.com>
To: Peter Stuge <peter@stuge.se>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] gitweb: Add js=1 before an URI fragment to fix line number links
Date: Mon, 26 Sep 2011 16:06:31 -0700 [thread overview]
Message-ID: <7vaa9q29ag.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1317060642-25488-1-git-send-email-peter@stuge.se> (Peter Stuge's message of "Mon, 26 Sep 2011 20:10:42 +0200")
Peter Stuge <peter@stuge.se> writes:
> -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](#.*)?$/;
Let's not repeat the regexp in the comment (badness you inherited from the
original).
Regarding the "we already have the js=0 or js=1 in the URL" check here...
> +var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
... I am wondering who guarantees that this js=[01] is the last parameter
before the fragment identifier. The answer obviously is "the way the
current code is written using replace() method on link.href", but that is
somewhat disturbing, because it is not clear what should happen, short of
total rewrite of the code around this, when somebody needs to include
another variable, say xx=[01], just like the js=[01] you are fixing here,
in the resulting URL. In other words, this fixLinks() logic does not seem
to scale and also looks brittle.
The patch itself looks correct as a short-term fix, though.
Thanks.
next prev parent reply other threads:[~2011-09-26 23:06 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 ` [PATCH] gitweb: Fix links to lines in blobs when javascript-actions are enabled Peter Stuge
2011-09-27 17:17 ` 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 [this message]
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=7vaa9q29ag.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peter@stuge.se \
/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).