Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix remaining domain regexes (#3783)
Browse files Browse the repository at this point in the history
This is a followup to 2bd42be that applies the same fix to other regular expressions
  • Loading branch information
ianb authored and jaredhirsch committed Nov 15, 2017
1 parent eb60a43 commit 5089187
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions addon/webextension/domainFromUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ this.domainFromUrl = (function() {
domain = "unknown";
}
}
if (domain.search(/^[a-z0-9.-_]{1,1000}$/i) === -1) {
if (domain.search(/^[a-z0-9._-]{1,1000}$/i) === -1) {
// Probably a unicode domain; we could use punycode but it wouldn't decode
// well in the URL anyway. Instead we'll punt.
domain = domain.replace(/[^a-z0-9.-_]/ig, "");
domain = domain.replace(/[^a-z0-9._-]/ig, "");
if (!domain) {
domain = "site";
}
Expand Down
6 changes: 3 additions & 3 deletions shared/shot.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function isUrl(url) {
if ((/^view-source:/i).test(url)) {
return isUrl(url.substr("view-source:".length));
}
return (/^https?:\/\/[a-z0-9.-_]{1,8000}[a-z0-9](:[0-9]{1,8000})?\/?/i).test(url);
return (/^https?:\/\/[a-z0-9._-]{1,8000}[a-z0-9](:[0-9]{1,8000})?\/?/i).test(url);
}

function isValidClipImageUrl(url) {
Expand All @@ -48,7 +48,7 @@ function assertUrl(url) {
}

function isSecureWebUri(url) {
return (/^https?:\/\/[a-z0-9.-_]{1,8000}[a-z0-9](:[0-9]{1,8000})?\/?/i).test(url);
return (/^https?:\/\/[a-z0-9._-]{1,8000}[a-z0-9](:[0-9]{1,8000})?\/?/i).test(url);
}

function assertOrigin(url) {
Expand Down Expand Up @@ -129,7 +129,7 @@ function resolveUrl(base, url) {
}
if (url.indexOf("/") === 0) {
// Domain-relative URL
return (/^https?:\/\/[a-z0-9.-_]{1,4000}/i).exec(base)[0] + url;
return (/^https?:\/\/[a-z0-9._-]{1,4000}/i).exec(base)[0] + url;
}
// Otherwise, a full relative URL
while (url.indexOf("./") === 0) {
Expand Down
2 changes: 1 addition & 1 deletion static/js/wantsauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ window.wantsauth = (function() {
// authentication. As a result we have to parse the URL on our own:
let maybeShotId = location.href.replace(/^https?:\/\/[^/]{1,4000}\//i, "");
maybeShotId = maybeShotId.replace(/\?.*/, "").replace(/#.{0,4000}/, "");
if (maybeShotId.search(/[a-z0-9]+\/[a-z0-9.-_]{1,4000}$/i) === -1) {
if (maybeShotId.search(/[a-z0-9]+\/[a-z0-9._-]{1,4000}$/i) === -1) {
// Not a shot ID, which should look like {stuff}/{stuff}
maybeShotId = null;
}
Expand Down

0 comments on commit 5089187

Please sign in to comment.