{"thread":{"id":"33442","subject":"[PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links","startedAt":"2013-04-08T20:09:48Z","lastAt":"2013-04-09T17:59:05Z","messageCount":4,"participants":["Jürgen Kreileder","Jakub Narębski"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"213600","messageId":"m2wqscbx83.fsf@blackdown.de","threadId":"33442","inReplyTo":null,"subject":"[PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links","fromName":"Jürgen Kreileder","fromEmail":"jk@blackdown.de","sentAt":"2013-04-08T20:09:48Z","receivedAt":"2013-04-08T20:09:48Z","isPatch":true,"sender":{"key":"jk@blackdown.de","avatar":"https://avatars.githubusercontent.com/u/4390544?v=4"},"body":"Don't add js parameters to links outside of gitweb itself.\n\nSigned-off-by: Jürgen Kreileder <jk@blackdown.de>\n---\n gitweb/gitweb.perl                       |    2 +-\n gitweb/static/js/javascript-detection.js |    4 ++--\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 1309196..f0912d7 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -4165,7 +4165,7 @@ sub git_footer_html {\n \t\tprint qq!<script type=\"text/javascript\">\\n!.\n \t\t      qq!window.onload = function () {\\n!;\n \t\tif (gitweb_check_feature('javascript-actions')) {\n-\t\t\tprint qq!\tfixLinks();\\n!;\n+\t\t\tprint qq!\tfixLinks('$my_url');\\n!;\n \t\t}\n \t\tif ($jstimezone && $tz_cookie && $datetime_class) {\n \t\t\tprint qq!\tvar tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\\n!. # in days\ndiff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js\nindex fa2596f..36964ad 100644\n--- a/gitweb/static/js/javascript-detection.js\n+++ b/gitweb/static/js/javascript-detection.js\n@@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;\n  *\n  * @globals jsExceptionsRe\n  */\n-function fixLinks() {\n+function fixLinks(baseurl) {\n \tvar allLinks = document.getElementsByTagName(\"a\") || document.links;\n \tfor (var i = 0, len = allLinks.length; i < len; i++) {\n \t\tvar link = allLinks[i];\n-\t\tif (!jsExceptionsRe.test(link)) {\n+\t\tif (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {\n \t\t\tlink.href = link.href.replace(/(#|$)/,\n \t\t\t\t(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');\n \t\t}\n-- \n1.7.10.4\n"},{"id":"213663","messageId":"516430D5.6030201@gmail.com","threadId":"33442","inReplyTo":"m2wqscbx83.fsf@blackdown.de","subject":"Re: [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2013-04-09T15:16:37Z","receivedAt":"2013-04-09T15:16:37Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jürgen Kreileder wrote:\n\n> Don't add js parameters to links outside of gitweb itself.\n\nHmmm... this limits adding ';js=(0|1)' to only links which begin with\n$my_url, i.e. absolute links beginning with gitweb's base URL.\n\nWouldn't that mean that most internal gitweb-generated links wouldn't\nget ';js=(0|1)'?  href(..., -full => 1) is not the default...\n\n> Signed-off-by: Jürgen Kreileder <jk@blackdown.de>\n> ---\n>  gitweb/gitweb.perl                       |    2 +-\n>  gitweb/static/js/javascript-detection.js |    4 ++--\n>  2 files changed, 3 insertions(+), 3 deletions(-)\n> \n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 1309196..f0912d7 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -4165,7 +4165,7 @@ sub git_footer_html {\n>  \t\tprint qq!<script type=\"text/javascript\">\\n!.\n>  \t\t      qq!window.onload = function () {\\n!;\n>  \t\tif (gitweb_check_feature('javascript-actions')) {\n> -\t\t\tprint qq!\tfixLinks();\\n!;\n> +\t\t\tprint qq!\tfixLinks('$my_url');\\n!;\n>  \t\t}\n>  \t\tif ($jstimezone && $tz_cookie && $datetime_class) {\n>  \t\t\tprint qq!\tvar tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\\n!. # in days\n> diff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js\n> index fa2596f..36964ad 100644\n> --- a/gitweb/static/js/javascript-detection.js\n> +++ b/gitweb/static/js/javascript-detection.js\n> @@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;\n>   *\n>   * @globals jsExceptionsRe\n>   */\n> -function fixLinks() {\n> +function fixLinks(baseurl) {\n>  \tvar allLinks = document.getElementsByTagName(\"a\") || document.links;\n>  \tfor (var i = 0, len = allLinks.length; i < len; i++) {\n>  \t\tvar link = allLinks[i];\n> -\t\tif (!jsExceptionsRe.test(link)) {\n> +\t\tif (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {\n>  \t\t\tlink.href = link.href.replace(/(#|$)/,\n>  \t\t\t\t(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');\n>  \t\t}\n> \n\n\n-- \nJakub Narębski\n"},{"id":"213686","messageId":"m2mwt7a8tz.fsf@zahir.fritz.box","threadId":"33442","inReplyTo":"516430D5.6030201@gmail.com","subject":"Re: [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links","fromName":"Jürgen Kreileder","fromEmail":"jk@blackdown.de","sentAt":"2013-04-09T17:54:16Z","receivedAt":"2013-04-09T17:54:16Z","isPatch":true,"sender":{"key":"jk@blackdown.de","avatar":"https://avatars.githubusercontent.com/u/4390544?v=4"},"body":"Jakub Narębski <jnareb@gmail.com> writes:\n\n> Jürgen Kreileder wrote:\n>\n>> Don't add js parameters to links outside of gitweb itself.\n>\n> Hmmm... this limits adding ';js=(0|1)' to only links which begin with\n> $my_url, i.e. absolute links beginning with gitweb's base URL.\n>\n> Wouldn't that mean that most internal gitweb-generated links wouldn't\n> get ';js=(0|1)'?  href(..., -full => 1) is not the default...\n\nNo, link.href is always absolute in JavaScript - even if the emitted URL\nwas relative.\n\nOld: https://git.blackdown.de/old.cgi?p=contactalbum.git;a=summary;js=1\nNew: https://git.blackdown.de/?p=contactalbum.git;a=summary;js=1\n\nWith the old version the external links in the description got ';js=1'\nappended.  With the new version, ';js=1' isn't on those links.\nOther links are the same in both versions.\n\n>> Signed-off-by: Jürgen Kreileder <jk@blackdown.de>\n>> ---\n>>  gitweb/gitweb.perl                       |    2 +-\n>>  gitweb/static/js/javascript-detection.js |    4 ++--\n>>  2 files changed, 3 insertions(+), 3 deletions(-)\n>> \n>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n>> index 1309196..f0912d7 100755\n>> --- a/gitweb/gitweb.perl\n>> +++ b/gitweb/gitweb.perl\n>> @@ -4165,7 +4165,7 @@ sub git_footer_html {\n>>  \t\tprint qq!<script type=\"text/javascript\">\\n!.\n>>  \t\t      qq!window.onload = function () {\\n!;\n>>  \t\tif (gitweb_check_feature('javascript-actions')) {\n>> -\t\t\tprint qq!\tfixLinks();\\n!;\n>> +\t\t\tprint qq!\tfixLinks('$my_url');\\n!;\n>>  \t\t}\n>>  \t\tif ($jstimezone && $tz_cookie && $datetime_class) {\n>>  \t\t\tprint qq!\tvar tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\\n!. # in days\n>> diff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js\n>> index fa2596f..36964ad 100644\n>> --- a/gitweb/static/js/javascript-detection.js\n>> +++ b/gitweb/static/js/javascript-detection.js\n>> @@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;\n>>   *\n>>   * @globals jsExceptionsRe\n>>   */\n>> -function fixLinks() {\n>> +function fixLinks(baseurl) {\n>>  \tvar allLinks = document.getElementsByTagName(\"a\") || document.links;\n>>  \tfor (var i = 0, len = allLinks.length; i < len; i++) {\n>>  \t\tvar link = allLinks[i];\n>> -\t\tif (!jsExceptionsRe.test(link)) {\n>> +\t\tif (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {\n>>  \t\t\tlink.href = link.href.replace(/(#|$)/,\n>>  \t\t\t\t(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');\n>>  \t\t}\n>> \n"},{"id":"213690","messageId":"516456E9.9070309@gmail.com","threadId":"33442","inReplyTo":"m2mwt7a8tz.fsf@zahir.fritz.box","subject":"Re: [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2013-04-09T17:59:05Z","receivedAt":"2013-04-09T17:59:05Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 09.04.2013 19:54, Jürgen Kreileder napisał:\n> Jakub Narębski <jnareb@gmail.com> writes:\n> \n>> Jürgen Kreileder wrote:\n>>\n>>> Don't add js parameters to links outside of gitweb itself.\n>>\n>> Hmmm... this limits adding ';js=(0|1)' to only links which begin with\n>> $my_url, i.e. absolute links beginning with gitweb's base URL.\n>>\n>> Wouldn't that mean that most internal gitweb-generated links wouldn't\n>> get ';js=(0|1)'?  href(..., -full => 1) is not the default...\n> \n> No, link.href is always absolute in JavaScript - even if the emitted URL\n> was relative.\n\nThanks, I didn't know that.\n\nSo, with that explanation:\n\nAcked-by: Jakub Narebski <jnareb@gmail.com>\n\n> Old: https://git.blackdown.de/old.cgi?p=contactalbum.git;a=summary;js=1\n> New: https://git.blackdown.de/?p=contactalbum.git;a=summary;js=1\n> \n> With the old version the external links in the description got ';js=1'\n> appended.  With the new version, ';js=1' isn't on those links.\n> Other links are the same in both versions.\n\nThanks.  This is a nice solution for a problem which I didn't know\nhow to solve (I was thinking about using <a class=\"internal\" ...>,\nbut your solution is better).\n\n-- \nJakub Narębski\n"}]}