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

url: update the processing in the scheme state. #11887

Closed
wants to merge 2 commits into from

Conversation

watilde
Copy link
Member

@watilde watilde commented Mar 17, 2017

Fix #11785. I've updated the processing in the scheme state to follow the specification and synchronized url-setter-tests with upstream.

While I was testing added tests, I noticed that the current state machine of Node.js doesn't parse URL correctly for pathname. For example:

var url = new URL('ssh://example.net')
url.pathname
// expected: //example.net
// actual: '/'

So I got rid of the following test for this time.

{
  "href": "ssh://example.net",
  "new_value": "file",
  "expected": {
    "href": "ssh://example.net",
    "protocol": "ssh:"
  }
},

I will work on it later.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests are included
  • commit message follows [commit guidelines][]
Affected core subsystem(s)

url, test

@watilde watilde added c++ Issues and PRs that require attention from people who are familiar with C++. test Issues and PRs related to the tests. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Mar 17, 2017
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. dont-land-on-v4.x whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Mar 17, 2017
@watilde
Copy link
Member Author

watilde commented Mar 17, 2017

cc @nodejs/url

@TimothyGu
Copy link
Member

The returning is handled in the JS layer. You might want to update that instead.

@watilde
Copy link
Member Author

watilde commented Mar 17, 2017

Oh that's nice. I will update the commit then!

@watilde watilde removed the c++ Issues and PRs that require attention from people who are familiar with C++. label Mar 17, 2017
@watilde
Copy link
Member Author

watilde commented Mar 17, 2017

@TimothyGu I've updated the commits to handling it in JS layer.

Well, I'm not sure those steps should be handled in the scheme state or not, but at least the spec expects it as scheme state checking. What are your thoughts on?

@@ -133,6 +133,12 @@ function onParseProtocolComplete(flags, protocol, username, password,
if ((s && !newIsSpecial) || (!s && newIsSpecial)) {
return;
}
if (protocol === 'file:' && (username || password || port > -1)) {
Copy link
Member

Choose a reason for hiding this comment

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

port can only be >= 0 or undefined, since the C++ layer sets port to undefined if it is -1, and you should probably check ctx.username and ctx.password instead of username and password since IIRC the C++ layer doesn't pass those into the callback if it's unneeded.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. +1

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right! I will update it. Thanks 😺

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I've updated.

@watilde
Copy link
Member Author

watilde commented Mar 17, 2017

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

LGTM other than the nit.

@@ -133,6 +133,14 @@ function onParseProtocolComplete(flags, protocol, username, password,
if ((s && !newIsSpecial) || (!s && newIsSpecial)) {
return;
}
if (protocol === 'file:' &&
(ctx.username || ctx.password || ctx.port !== undefined)
) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: stylistically it's more common to write it as:

if (protocol === 'file:' &&
    (ctx.username || ctx.password || ctx.port !== undefined)) {

Since file URLs can not have `username/password/port`,
the specification was updated to restrict setting protocol to "file".

Refs: whatwg/url#269
Fixes: nodejs#11785
Synchronize url-setter-test to upstream.

Refs: web-platform-tests/wpt#5112
@watilde
Copy link
Member Author

watilde commented Mar 18, 2017

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

If there are test cases that don't pass at the moment, you can change url-setter-tests.json to a js file with module.exports, then put those test cases in that file and comment them out, like what https://github.com/nodejs/node/blob/master/test/fixtures/url-tests.js does

@watilde
Copy link
Member Author

watilde commented Mar 20, 2017

@joyeecheung that's nice! I will sync the setter url fixture in my next patch, will rename the file at the same time then :)

@watilde
Copy link
Member Author

watilde commented Mar 20, 2017

Landed in 60c8a35 and cab58fe.

@watilde watilde closed this Mar 20, 2017
watilde added a commit that referenced this pull request Mar 20, 2017
Since file URLs can not have `username/password/port`,
the specification was updated to restrict setting protocol to "file".

Refs: whatwg/url#269
Fixes: #11785
PR-URL: #11887
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
watilde added a commit that referenced this pull request Mar 20, 2017
Synchronize url-setter-test to upstream.

Refs: web-platform-tests/wpt#5112
PR-URL: #11887
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@watilde watilde deleted the feature/file-url branch March 20, 2017 18:46
jungx098 pushed a commit to jungx098/node that referenced this pull request Mar 21, 2017
Since file URLs can not have `username/password/port`,
the specification was updated to restrict setting protocol to "file".

Refs: whatwg/url#269
Fixes: nodejs#11785
PR-URL: nodejs#11887
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
jungx098 pushed a commit to jungx098/node that referenced this pull request Mar 21, 2017
Synchronize url-setter-test to upstream.

Refs: web-platform-tests/wpt#5112
PR-URL: nodejs#11887
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 28, 2017
Since file URLs can not have `username/password/port`,
the specification was updated to restrict setting protocol to "file".

Refs: whatwg/url#269
Fixes: #11785
PR-URL: #11887
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 28, 2017
Synchronize url-setter-test to upstream.

Refs: web-platform-tests/wpt#5112
PR-URL: #11887
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Mar 28, 2017
watilde added a commit to watilde/node that referenced this pull request Apr 2, 2017
watilde added a commit to watilde/node that referenced this pull request Apr 2, 2017
Updates:
+ Bring tests url-setter-tests from WPT, and put it as JavaScript
+ Comment out unpassed tests

Refs: web-platform-tests/wpt#5112
Refs: nodejs#11887
watilde added a commit that referenced this pull request Apr 3, 2017
Refs: web-platform-tests/wpt#4586
Refs: #11887
PR-URL: #12058
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
watilde added a commit that referenced this pull request Apr 3, 2017
Updates:
+ Bring tests url-setter-tests from WPT, and put it as JavaScript
+ Comment out unpassed tests

Refs: web-platform-tests/wpt#5112
Refs: #11887
PR-URL: #12058
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Apr 10, 2017
Updates:
+ Bring tests url-setter-tests from WPT, and put it as JavaScript
+ Comment out unpassed tests

Refs: web-platform-tests/wpt#5112
Refs: nodejs#11887
PR-URL: nodejs#12058
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
@italoacasas italoacasas mentioned this pull request Apr 10, 2017
2 tasks
TimothyGu pushed a commit to TimothyGu/node that referenced this pull request Apr 25, 2017
PR-URL: nodejs#12507
Refs: web-platform-tests/wpt#4586
Refs: nodejs#11887
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this pull request May 1, 2017
PR-URL: #12507
Refs: web-platform-tests/wpt#4586
Refs: #11887
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants