git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitweb: Add js=1 before an URI fragment to fix line number links

From
Jakub Narebski <jnareb@gmail.com>
Date
Sep 26, 2011, 23:19 UTC
Message-ID
<m339fiq4dx.fsf@localhost.localdomain>
In-Reply-To
<1317060642-25488-1-git-send-email-peter@stuge.se>
Peter Stuge <peter@stuge.se> writes:
It really needs a proper commit message.  Perhaps something like this:
  The fixLinks() function in javascript-detection.js is supposed to
  add 'js' query parameter with a value of 1 to each link that does
  not have 'js' query parameter already.
  However it didn't take into account the fact that URI can have
  'fragment' part.  It meant that:
  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 <peter@stuge.se>
For what it is worth it
Acked-by: Jakub Narebski <jnareb@gmail.com>
Show 33 quoted lines
> ---
>  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');
>  		}
>  	}
>  }
> -- 
> 1.7.4.1.343.ga91df.dirty
> 
-- 
Jakub Narębski                      mailto:jnareb@fuw.edu.pl
 ZTHiL IFT UW                       http://info.fuw.edu.pl/~jnareb/
Previous: Peter Stuge
Message 14 of 14 in “gitweb: Add js=1 before an URI fragment to fix line number links”
  1. gitweb: Add js=1 before an URI fragment to fix line number linksPeter Stuge, Sep 26, 2011
  2. Junio C HamanoSep 26, 2011
  3. Peter StugeSep 26, 2011
  4. Junio C HamanoSep 26, 2011
  5. Peter StugeSep 26, 2011
  6. Johannes SixtSep 27, 2011
  7. Peter StugeSep 27, 2011
  8. gitweb: Fix links to lines in blobs when javascript-actions are enabledPeter Stuge, Sep 27, 2011
  9. Junio C HamanoSep 27, 2011
  10. Peter StugeSep 28, 2011
  11. Junio C HamanoSep 27, 2011
  12. Junio C HamanoSep 26, 2011
  13. Peter StugeSep 26, 2011
  14. Jakub NarebskiSep 26, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.