Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linkify can parse anchor tag #596

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,30 @@
};

var linkify = function(input) {
var regex = /(https?|ftp|file):\/\/[-a-zA-Z0-9+&@#/%?=~_|!:,.;$]*[-a-zA-Z0-9+&@#/%=~_|$]/g;
input = input.replace(regex, "<a href='$&' target='_blank'>$&</a>");
// Define the regex to check for the specific OMERO HTML-escaped anchor tag format
// input user: <a href="https://example.com">Test</a>
// OMERO HTML-escaped input: &lt;a href="https://example.com"&gt;Test&lt;/a&gt;
const anchorCheckRegex = /^&lt;a\s+href=([^&]+)&gt;([^&]+)&lt;\/a&gt;$/;


if(!anchorCheckRegex.test(input)){
var regex = /(https?|ftp|file):\/\/[-a-zA-Z0-9+&@#/%?=~_{}[\]|!:,.;$]*[-a-zA-Z0-9+&@#/%=~_{}[\]|$]/g;
input = input.replace(regex, "<a href='$&' target='_blank'>$&</a>");
}else{ // given input is a html <a> tag
// unescape HTML entities of <a> tag
input= input.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&')
Comment on lines +75 to +77

Check failure

Code scanning / CodeQL

Double escaping or unescaping High

This replacement may produce '&' characters that are double-unescaped
here
.
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");

// Use regex to match and transform the <a> tag
const anchorRegex = /<a\s+href="(.*?)">(.*?)<\/a>/i;

// add target="_blank"
input = input.replace(anchorRegex, "<a href='$1' target='_blank'>$2</a>");
}

return linkObjects(input);
};
var linkObjects = function(input) {
Expand Down
Loading