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 authored Jan 3, 2017
1 parent 9096654 commit 7d80c7d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 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 [373dbe](https://github.com/whatwg/url/tree/373dbedbbf0596f723ce8a195923da98b698aeb0).
whatwg-url is currently up to date with the URL spec up to commit [5e0b05](https://github.com/whatwg/url/tree/5e0b05e95a81fdd539c7b1bf97e69b3df701384f).

## API

Expand Down
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 = "e0012406859014e8f31dbaf12122d0cd10249db4";

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
35 changes: 18 additions & 17 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
this.url = {
scheme: "",
username: "",
password: null,
password: "",
host: null,
port: null,
path: [],
Expand Down Expand Up @@ -498,6 +498,7 @@ function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
this.buffer = "";
this.atFlag = false;
this.arrFlag = false;
this.passwordTokenSeenFlag = false;

this.input = punycode.ucs2.decode(this.input);

Expand Down Expand Up @@ -723,12 +724,12 @@ URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr)
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(":") && !this.passwordTokenSeenFlag) {
this.passwordTokenSeenFlag = true;
continue;
}
const encodedCodePoints = encodeChar(codePoint, isUserInfoEncode);
if (this.url.password !== null) {
if (this.passwordTokenSeenFlag) {
this.url.password += encodedCodePoints;
} else {
this.url.username += encodedCodePoints;
Expand Down Expand Up @@ -1071,14 +1072,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 @@ -1171,14 +1176,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 7d80c7d

Please sign in to comment.