Skip to contentSkip to conversation

gitweb: Don't append ';js=(0|1)' to external links

PATCH In review Jürgen Kreileder 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 gitweb: Don't append ';js=(0|1)' to external links

Don't add js parameters to links outside of gitweb itself.

---
 gitweb/gitweb.perl                       |    2 +-
 gitweb/static/js/javascript-detection.js |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
gitweb/gitweb.perl +1 -1
index 1309196..f0912d7 100755
@@ -4165,7 +4165,7 @@ sub git_footer_html {
 		print qq!<script type="text/javascript">\n!.
 		      qq!window.onload = function () {\n!;
 		if (gitweb_check_feature('javascript-actions')) {
-			print qq!	fixLinks();\n!;
+			print qq!	fixLinks('$my_url');\n!;
 		}
 		if ($jstimezone && $tz_cookie && $datetime_class) {
 			print qq!	var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
gitweb/static/js/javascript-detection.js +2 -2
index fa2596f..36964ad 100644
@@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
  *
  * @globals jsExceptionsRe
  */
-function fixLinks() {
+function fixLinks(baseurl) {
 	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)) {
+		if (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {
 			link.href = link.href.replace(/(#|$)/,
 				(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
 		}
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 1 line · Jürgen Kreileder

Don't add js parameters to links outside of gitweb itself.

Hmmm... this limits adding ';js=(0|1)' to only links which begin with $my_url, i.e. absolute links beginning with gitweb's base URL.

Wouldn't that mean that most internal gitweb-generated links wouldn't get ';js=(0|1)'? href(..., -full => 1) is not the default...

Quoted 38 lines
---
 gitweb/gitweb.perl                       |    2 +-
 gitweb/static/js/javascript-detection.js |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
gitweb/gitweb.perl +1 -1
index 1309196..f0912d7 100755
@@ -4165,7 +4165,7 @@ sub git_footer_html {
 		print qq!<script type="text/javascript">\n!.
 		      qq!window.onload = function () {\n!;
 		if (gitweb_check_feature('javascript-actions')) {
-			print qq!	fixLinks();\n!;
+			print qq!	fixLinks('$my_url');\n!;
 		}
 		if ($jstimezone && $tz_cookie && $datetime_class) {
 			print qq!	var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
gitweb/static/js/javascript-detection.js +2 -2
index fa2596f..36964ad 100644
@@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
  *
  * @globals jsExceptionsRe
  */
-function fixLinks() {
+function fixLinks(baseurl) {
 	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)) {
+		if (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {
 			link.href = link.href.replace(/(#|$)/,
 				(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
 		}
Signature · 1 line
Jakub Narębski
#2 lore raw
Quoted 9 lines · Jakub Narębski
Quoted 1 line · Jürgen Kreileder

Don't add js parameters to links outside of gitweb itself.

Hmmm... this limits adding ';js=(0|1)' to only links which begin with $my_url, i.e. absolute links beginning with gitweb's base URL.

Wouldn't that mean that most internal gitweb-generated links wouldn't get ';js=(0|1)'? href(..., -full => 1) is not the default...

No, link.href is always absolute in JavaScript - even if the emitted URL was relative.

Old: https://git.blackdown.de/old.cgi?p=contactalbum.git;a=summary;js=1
New: https://git.blackdown.de/?p=contactalbum.git;a=summary;js=1

With the old version the external links in the description got ';js=1' appended. With the new version, ';js=1' isn't on those links. Other links are the same in both versions.

Quoted 38 lines
Quoted 38 lines
---
 gitweb/gitweb.perl                       |    2 +-
 gitweb/static/js/javascript-detection.js |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
gitweb/gitweb.perl +1 -1
index 1309196..f0912d7 100755
@@ -4165,7 +4165,7 @@ sub git_footer_html {
 		print qq!<script type="text/javascript">\n!.
 		      qq!window.onload = function () {\n!;
 		if (gitweb_check_feature('javascript-actions')) {
-			print qq!	fixLinks();\n!;
+			print qq!	fixLinks('$my_url');\n!;
 		}
 		if ($jstimezone && $tz_cookie && $datetime_class) {
 			print qq!	var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
gitweb/static/js/javascript-detection.js +2 -2
index fa2596f..36964ad 100644
@@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
  *
  * @globals jsExceptionsRe
  */
-function fixLinks() {
+function fixLinks(baseurl) {
 	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)) {
+		if (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {
 			link.href = link.href.replace(/(#|$)/,
 				(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
 		}
#3 lore raw
Quoted 6 lines · Jürgen Kreileder
Quoted 4 lines · Jakub Narębski
Quoted 1 line · Jürgen Kreileder

Don't add js parameters to links outside of gitweb itself.

Quoted 8 lines
Quoted 5 lines

Hmmm... this limits adding ';js=(0|1)' to only links which begin with $my_url, i.e. absolute links beginning with gitweb's base URL.

Wouldn't that mean that most internal gitweb-generated links wouldn't get ';js=(0|1)'? href(..., -full => 1) is not the default...

No, link.href is always absolute in JavaScript - even if the emitted URL was relative.

Thanks, I didn't know that.

So, with that explanation:

Quoted 6 lines

Old: https://git.blackdown.de/old.cgi?p=contactalbum.git;a=summary;js=1
New: https://git.blackdown.de/?p=contactalbum.git;a=summary;js=1

With the old version the external links in the description got ';js=1' appended. With the new version, ';js=1' isn't on those links. Other links are the same in both versions.

Thanks. This is a nice solution for a problem which I didn't know how to solve (I was thinking about using <a class="internal" ...>, but your solution is better).

Signature · 1 line
Jakub Narębski