Skip to content

Commit

Permalink
Artifact link splitting is now case-insensitive.
Browse files Browse the repository at this point in the history
The splitting by '%2F' needs to be case-insensitive. ADO sometimes uses
'%2f' instead. E.g. seen for automatically linked commits.
  • Loading branch information
Sedeniono committed Mar 12, 2024
1 parent 65e963b commit 3c1ad89
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/HistoryDiffPageScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ function EscapeHtml(string) {
});
}

// Escapes some text so that it gets interpreted as normal text in a regex.
function EscapeForRegex(str)
{
// https://stackoverflow.com/a/67227435
return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

const gStyleRegex = /\<style\>.*?\<\/style\>/gms;

function RemoveStyle(string)
{
return String(string).replace(gStyleRegex, '');
return String(string).replace(/\<style\>.*?\<\/style\>/gms, '');
}


Expand Down Expand Up @@ -501,12 +506,14 @@ function SplitArtifactIdForRouteUrl(artifactId, numComponents)
// Like the standard String.split() function, it returns an array with at most 'limit' elements.
// But if the given 'str' contains more separators that specified by 'limit', the last array element
// contains all the remaining string without being split.
// Additionally, the split happens case-insensitive.
function SplitWithRemainder(str, separator, limit)
{
if (limit === 0) {
return [];
}
const fullySplit = str.split(separator);
// 'i' for case-insensitive. https://stackoverflow.com/a/67227435
const fullySplit = str.split(new RegExp(EscapeForRegex(separator), 'i'));
if (!limit) {
return fullySplit;
}
Expand Down

0 comments on commit 3c1ad89

Please sign in to comment.