Skip to content

Commit

Permalink
Spec update: get rid of null passwords
Browse files Browse the repository at this point in the history
This aligns with whatwg/url#186.
  • Loading branch information
domenic committed Dec 29, 2016
1 parent 31152b5 commit ef36fc9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
4 changes: 0 additions & 4 deletions lib/URL-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ exports.implementation = class URLImpl {
}

get password() {
if (this._url.password === null) {
return "";
}

return this._url.password;
}

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 @@ -15,7 +15,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 = "5be497b5f5a7036e26dc14739aa8d42f643cf94f";
const commitHash = "f89847d4df8bb732a51c0669b3d4fa6718c71e54";

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
36 changes: 19 additions & 17 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
this.url = {
scheme: "",
username: "",
password: null,
password: "",
host: null,
port: null,
path: [],
Expand Down Expand Up @@ -707,17 +707,19 @@ URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr)
}
this.atFlag = true;

let passwordTokenSeenFlag = false;

// careful, this is based on buffer and has its own pointer (this.pointer != pointer) and inner chars
const len = countSymbols(this.buffer);
for (let pointer = 0; pointer < len; ++pointer) {
const codePoint = this.buffer.codePointAt(pointer);

if (codePoint === p(":") && this.url.password === null) {
this.url.password = "";
if (codePoint === p(":") && !passwordTokenSeenFlag) {
passwordTokenSeenFlag = true;
continue;
}
const encodedCodePoints = encodeChar(codePoint, isUserInfoEncode);
if (this.url.password !== null) {
if (passwordTokenSeenFlag) {
this.url.password += encodedCodePoints;
} else {
this.url.username += encodedCodePoints;
Expand Down Expand Up @@ -1060,14 +1062,18 @@ URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
function serializeURL(url, excludeFragment) {
let output = url.scheme + ":";
if (url.host !== null) {
output += "//" + url.username;
if (url.password !== null) {
output += ":" + url.password;
}
if (url.username !== "" || url.password !== null) {
output += "//";

if (url.username !== "" || url.password !== "") {
output += url.username;
if (url.password !== "") {
output += ":" + url.password;
}
output += "@";
}

output += serializeHost(url.host);

if (url.port !== null) {
output += ":" + url.port;
}
Expand Down Expand Up @@ -1160,14 +1166,10 @@ module.exports.setTheUsername = function (url, username) {
};

module.exports.setThePassword = function (url, password) {
if (password === "") {
url.password = null;
} else {
url.password = "";
const decoded = punycode.ucs2.decode(password);
for (let i = 0; i < decoded.length; ++i) {
url.password += encodeChar(decoded[i], isUserInfoEncode);
}
url.password = "";
const decoded = punycode.ucs2.decode(password);
for (let i = 0; i < decoded.length; ++i) {
url.password += encodeChar(decoded[i], isUserInfoEncode);
}
};

Expand Down

0 comments on commit ef36fc9

Please sign in to comment.