Skip to content

Commit

Permalink
Spec update: cleanup API for file and non-special URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Feb 2, 2017
1 parent cd44d02 commit f3de3fa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
14 changes: 9 additions & 5 deletions lib/URL-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports.implementation = class URLImpl {
}

set username(v) {
if (this._url.host === null || this._url.cannotBeABaseURL) {
if (this._url.host === null || this._url.host === "" || this._url.cannotBeABaseURL || this._url.scheme === "file") {
return;
}

Expand All @@ -66,7 +66,7 @@ exports.implementation = class URLImpl {
}

set password(v) {
if (this._url.host === null || this._url.cannotBeABaseURL) {
if (this._url.host === null || this._url.host === "" || this._url.cannotBeABaseURL || this._url.scheme === "file") {
return;
}

Expand All @@ -92,7 +92,9 @@ exports.implementation = class URLImpl {
return;
}

usm.basicURLParse(v, { url: this._url, stateOverride: "host" });
const hostState = this._url.scheme === "file" ? "file host" : "host";

usm.basicURLParse(v, { url: this._url, stateOverride: hostState });
}

get hostname() {
Expand All @@ -108,7 +110,9 @@ exports.implementation = class URLImpl {
return;
}

usm.basicURLParse(v, { url: this._url, stateOverride: "hostname" });
const hostState = this._url.scheme === "file" ? "file host" : "hostname";

usm.basicURLParse(v, { url: this._url, stateOverride: hostState });
}

get port() {
Expand All @@ -120,7 +124,7 @@ exports.implementation = class URLImpl {
}

set port(v) {
if (this._url.host === null || this._url.cannotBeABaseURL || this._url.scheme === "file") {
if (this._url.host === null || this._url.host === "" || this._url.cannotBeABaseURL || this._url.scheme === "file") {
return;
}

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 = "8be87380efb01f5fde485511b8df80fce93090d5";
const commitHash = "512b95eae6cbfdef4c6faf4d167aaf72671f35ea";

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
26 changes: 21 additions & 5 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
if (isSpecial(this.url) && this.buffer === "") {
this.parseError = true;
return failure;
} else if (this.stateOverride && this.buffer === "" &&
(this.url.username === "" || this.url.password === "" || this.url.port !== null)) {
this.parseError = true;
return false;
}

const host = parseURLHost(this.buffer, isSpecial(this.url));
Expand Down Expand Up @@ -948,19 +952,31 @@ URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) {
URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) {
if (isNaN(c) || c === p("/") || c === p("\\") || c === p("?") || c === p("#")) {
--this.pointer;
// don't need to count symbols here since we check ASCII values
if (isWindowsDriveLetterString(this.buffer)) {
if (!this.stateOverride && isWindowsDriveLetterString(this.buffer)) {
this.parseError = true;
this.state = "path";
} else if (this.buffer === "") {
if (this.stateOverride && (this.url.username !== "" || this.url.password !== "")) {
this.parseError = true;
return false;
}
this.url.host = "";
if (this.stateOverride) {
return false;
}
this.state = "path start";
} else {
const host = parseHost(this.buffer);
let host = parseHost(this.buffer);
if (host === failure) {
return failure;
}
if (host !== "localhost") {
this.url.host = host;
if (host === "localhost") {
host = "";
}
this.url.host = host;

if (this.stateOverride) {
return false;
}

this.buffer = "";
Expand Down

0 comments on commit f3de3fa

Please sign in to comment.