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 cad6187 commit bf0b188
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe

## Current Status

whatwg-url is currently up to date with the URL spec up to commit [cf616f](https://github.com/whatwg/url/commit/cf616f9d3fca44bd5329e992519a4236a39b0cb7).
whatwg-url is currently up to date with the URL spec up to commit [cdbcce](https://github.com/whatwg/url/commit/cdbcce62045b1614695b00cc0427f6fb0fc7ed03).

## API

Expand Down
2 changes: 1 addition & 1 deletion scripts/get-latest-platform-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const request = require("request");
// 1. Go to https://github.com/w3c/web-platform-tests/tree/master/url
// 2. Press "y" on your keyboard to get a permalink
// 3. Copy the commit hash
const commitHash = "0e6a90f2307694da7cd1e551852d25a75be3be11";
const commitHash = "8f953c7cc884ae4277428fa8c72131563d31c590";

const sourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/urltestdata.json`;
const setterSourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/setters_tests.json`;
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, isSpecialArg, 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 (!isSpecialArg) {
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 @@ -818,7 +822,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 @@ -841,7 +845,7 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
return false;
}

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 @@ -976,7 +980,7 @@ URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) {
}
this.state = "path start";
} else {
let host = parseHost(this.buffer);
let host = parseHost(this.buffer, isSpecial(this.url));
if (host === failure) {
return failure;
}
Expand Down

0 comments on commit bf0b188

Please sign in to comment.