Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement isURLCodePoint #59

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@ function isASCIIHex(c) {
return isASCIIDigit(c) || (c >= 0x41 && c <= 0x46) || (c >= 0x61 && c <= 0x66);
}

function isURLCodePoint(c) {
return (
isASCIIAlphanumeric(c) ||
c === 0x21 ||
Copy link
Member

@Sebmaster Sebmaster Nov 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you switch these over to use the notation used in the URL spec (that is, use the literal chars, pass them through our conversion p transform). Optionally change it to an array (not sure if that makes copying them off the spec easier)?

c === 0x24 ||
(c >= 0x26 && c <= 0x2F) ||
c === 0x3A ||
c === 0x3B ||
c === 0x3D ||
c === 0x3F ||
c === 0x40 ||
c === 0x5F ||
c === 0x7E ||
(c >= 0xA0 && c <= 0xD7FF) ||
(c >= 0xE000 && c <= 0xFDCF) ||
(c >= 0xFDF0 && c <= 0xFFFD) ||
(c >= 0x10000 && c <= 0x1FFFD) ||
(c >= 0x20000 && c <= 0x2FFFD) ||
(c >= 0x30000 && c <= 0x3FFFD) ||
(c >= 0x40000 && c <= 0x4FFFD) ||
(c >= 0x50000 && c <= 0x5FFFD) ||
(c >= 0x60000 && c <= 0x6FFFD) ||
(c >= 0x70000 && c <= 0x7FFFD) ||
(c >= 0x80000 && c <= 0x8FFFD) ||
(c >= 0x90000 && c <= 0x9FFFD) ||
(c >= 0xA0000 && c <= 0xAFFFD) ||
(c >= 0xB0000 && c <= 0xBFFFD) ||
(c >= 0xC0000 && c <= 0xCFFFD) ||
(c >= 0xD0000 && c <= 0xDFFFD) ||
(c >= 0xE0000 && c <= 0xEFFFD) ||
(c >= 0xF0000 && c <= 0xFFFFD) ||
(c >= 0x100000 && c <= 0x10FFFD)
);
}

function isSingleDot(buffer) {
return buffer === "." || buffer.toLowerCase() === "%2e";
}
Expand Down Expand Up @@ -946,7 +981,9 @@ URLStateMachine.prototype["parse path"] = function parsePath(c) {
this.state = "fragment";
}
} else {
// TODO: If c is not a URL code point and not "%", parse error.
if (!isURLCodePoint(c) && c !== p("%")) {
this.parseError = true;
}

if (c === p("%") &&
(!isASCIIHex(this.input[this.pointer + 1]) ||
Expand Down Expand Up @@ -975,8 +1012,7 @@ URLStateMachine.prototype["parse cannot-be-a-base-URL path"] = function parseCan
this.url.fragment = "";
this.state = "fragment";
} else {
// TODO: Add: not a URL code point
if (!isNaN(c) && c !== p("%")) {
if (!isNaN(c) && !isURLCodePoint(c) && c !== p("%")) {
this.parseError = true;
}

Expand Down Expand Up @@ -1016,7 +1052,10 @@ URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) {
this.state = "fragment";
}
} else {
// TODO: If c is not a URL code point and not "%", parse error.
if (!isURLCodePoint(c) && c !== p("%")) {
this.parseError = true;
}

if (c === p("%") &&
(!isASCIIHex(this.input[this.pointer + 1]) ||
!isASCIIHex(this.input[this.pointer + 2]))) {
Expand All @@ -1034,7 +1073,10 @@ URLStateMachine.prototype["parse fragment"] = function parseFragment(c, cStr) {
} else if (c === 0x0) {
this.parseError = true;
} else {
// TODO: If c is not a URL code point and not "%", parse error.
if (!isURLCodePoint(c) && c !== "%") {
this.parseError = true;
}

if (c === p("%") &&
(!isASCIIHex(this.input[this.pointer + 1]) ||
!isASCIIHex(this.input[this.pointer + 2]))) {
Expand Down