Skip to content

Commit 28f5b98

Browse files
committed
Fix linkify to only link to proper URLs
This doesn't check for really well formed URLs, but it limits the matching to only allowed characters in URIs. It makes up for escapeForHtml() being already called, so it matches `&amp;` separately. Tested with: # '"> should be excluded 'https://github.com/os-autoinst/openQA' "https://github.com/os-autoinst/openQA.git" <https://github.com/os-autoinst/os-autoinst.git> # ) should be included https://de.wikipedia.org/wiki/Queen_(Band) # query strings should be included https://github.com/os-autoinst/openQA?foo=1%20&bar=*2
1 parent c2016a2 commit 28f5b98

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

assets/javascripts/anser-import.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
const module = {};
22

3+
// https://datatracker.ietf.org/doc/html/rfc3986#appendix-A
4+
function linkify(txt) {
5+
const re = /(https?:\/\/(?:[A-Za-z0-9#;/?:@=+$,_.!~*()[\]-]|&amp;|%[A-Ea-a0-9]{2})+)/gm;
6+
return txt.replace(re, function (str) {
7+
return '<a href="' + str + '">' + str + '</a>';
8+
});
9+
}
310
function ansiToHtml(data) {
4-
return Anser.linkify(Anser.ansiToHtml(Anser.escapeForHtml(data), {use_classes: true}));
11+
return linkify(Anser.ansiToHtml(Anser.escapeForHtml(data), {use_classes: true}));
512
}
613
function ansiToText(data) {
714
return Anser.ansiToText(data);

0 commit comments

Comments
 (0)