Skip to content

Commit

Permalink
Support base64 encoded URLs in anchors
Browse files Browse the repository at this point in the history
Closes #181
  • Loading branch information
sblask committed Mar 27, 2021
1 parent 30b6a0b commit 07cb560
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ test("base64 encoded URLs - in path", function(assert) {
assert.end();
});

test("base64 encoded URLs - in anchor", function(assert) {
const urlExceptions = [];
const parameterExceptions = [];
assert.equal(url.getRedirectTarget("http://" + "www.some.website.com" + "/#" + base64.encode(wwwTargetUrl), urlExceptions, parameterExceptions), "http://" + wwwTargetUrl);
assert.equal(url.getRedirectTarget("http://" + "www.some.website.com" + "/#" + base64.encode(wwwTargetUrl + "\n" + someTargetUrl), urlExceptions, parameterExceptions), "http://" + wwwTargetUrl);
assert.equal(url.getRedirectTarget("http://" + "www.some.website.com" + "/#" + base64.encode("http://" + someTargetUrl), urlExceptions, parameterExceptions), "http://" + someTargetUrl);
assert.equal(url.getRedirectTarget("http://" + "www.some.website.com" + "/#" + base64.encode("http://" + someTargetUrl) + "#some-fragment", urlExceptions, parameterExceptions), "http://" + someTargetUrl);
assert.end();
});

test("base64 encoded URLs - in path with junk in front of it", function(assert) {
const urlExceptions = [];
const parameterExceptions = [];
Expand Down
6 changes: 3 additions & 3 deletions url.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const url = (function(root) { // eslint-disable-line no-unused-vars
// the decoded string is needed
const base64CheckRegexp = new RegExp("^(?:" + possibleBase64PrefixesDecoded.join("|") + ")", "i");

const pathRegexpPlainProtocol = new RegExp("https?://.*?" + "(?:[^/][/]|\\?)" + "(" + possibleColonPrefixesString + ".*$" + ")", "i");
const pathRegexpEncodedProtocol = new RegExp("https?://.*?" + "(?:[^/][/]|\\?)" + "(" + possibleEncodedColonPrefixesString + "[^?&;#]*" + ")", "i");
const pathRegexpBase64Protocol = new RegExp("https?://.*?" + "(?:[^/][/]|\\?)" + base64JunkPrefix + "(" + possibleBase64PrefixesString + validBase64 + ")", "i");
const pathRegexpPlainProtocol = new RegExp("https?://.*?" + "(?:[^/][/]|\\?)" + "(" + possibleColonPrefixesString + ".*$" + ")", "i");
const pathRegexpEncodedProtocol = new RegExp("https?://.*?" + "(?:[^/][/]|\\?)" + "(" + possibleEncodedColonPrefixesString + "[^?&;#]*" + ")", "i");
const pathRegexpBase64Protocol = new RegExp("https?://.*?" + "(?:[^/][/]|[^#][#]|\\?)" + base64JunkPrefix + "(" + possibleBase64PrefixesString + validBase64 + ")", "i");

// %
const percentRegExp = new RegExp("%25", "i");
Expand Down

0 comments on commit 07cb560

Please sign in to comment.