Skip to content

Commit

Permalink
Spec update: percent-encode more in fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Oct 10, 2017
1 parent 18d92e9 commit 214b900
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
# node specific
node_modules/
npm-debug.log
package-lock.json

# project specific
coverage/
Expand Down
2 changes: 1 addition & 1 deletion scripts/get-latest-platform-tests.js
Expand Up @@ -19,7 +19,7 @@ process.on("unhandledRejection", err => {
// 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 = "5d149f011b36c84541186414c783f0ea18d14942";
const commitHash = "3879b2314eac71afe1054a63d0260aa16b5502a5";

// Have to use RawGit as JSDOM.fromURL checks Content-Type header.
const urlPrefix = `https://rawgit.com/w3c/web-platform-tests/${commitHash}/url/`;
Expand Down
17 changes: 11 additions & 6 deletions src/url-state-machine.js
Expand Up @@ -87,17 +87,22 @@ function isC0ControlPercentEncode(c) {
return c <= 0x1F || c > 0x7E;
}

const extraPathPercentEncodeSet = new Set([p(" "), p("\""), p("#"), p("<"), p(">"), p("?"), p("`"), p("{"), p("}")]);
function isPathPercentEncode(c) {
return isC0ControlPercentEncode(c) || extraPathPercentEncodeSet.has(c);
}

const extraUserinfoPercentEncodeSet =
new Set([p("/"), p(":"), p(";"), p("="), p("@"), p("["), p("\\"), p("]"), p("^"), p("|")]);
function isUserinfoPercentEncode(c) {
return isPathPercentEncode(c) || extraUserinfoPercentEncodeSet.has(c);
}

const extraFragmentPercentEncodeSet = new Set([p(" "), p("\""), p("<"), p(">"), p("`")]);
function isFragmentPercentEncode(c) {
return isC0ControlPercentEncode(c) || extraFragmentPercentEncodeSet.has(c);
}

const extraPathPercentEncodeSet = new Set([p("#"), p("?"), p("{"), p("}")]);
function isPathPercentEncode(c) {
return isFragmentPercentEncode(c) || extraPathPercentEncodeSet.has(c);
}

function percentEncodeChar(c, encodeSetPredicate) {
const cStr = String.fromCodePoint(c);

Expand Down Expand Up @@ -1148,7 +1153,7 @@ URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
this.parseError = true;
}

this.url.fragment += percentEncodeChar(c, isC0ControlPercentEncode);
this.url.fragment += percentEncodeChar(c, isFragmentPercentEncode);
}

return true;
Expand Down

0 comments on commit 214b900

Please sign in to comment.