Skip to content

Commit

Permalink
Fix linkify to only link to proper URLs
Browse files Browse the repository at this point in the history
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 `&`
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
  • Loading branch information
perlpunk committed Sep 11, 2024
1 parent c2016a2 commit 28f5b98
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion assets/javascripts/anser-import.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const module = {};

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

0 comments on commit 28f5b98

Please sign in to comment.