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

Commit

Permalink
Update domain name regex to allow - and _. (#3667)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba committed Oct 25, 2017
1 parent fa64832 commit 617b0c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 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
8 changes: 4 additions & 4 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 Expand Up @@ -209,7 +209,7 @@ class AbstractShot {

constructor(backend, id, attrs) {
attrs = attrs || {};
assert((/^[a-zA-Z0-9]{1,4000}\/[a-z0-9.-]{1,4000}$/).test(id), "Bad ID (should be alphanumeric):", JSON.stringify(id));
assert((/^[a-zA-Z0-9]{1,4000}\/[a-z0-9.-_]{1,4000}$/).test(id), "Bad ID (should be alphanumeric):", JSON.stringify(id));
this._backend = backend;
this._id = id;
this.origin = attrs.origin || null;
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 617b0c8

Please # to comment.