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: make WHATWG URL implementation more spec compliant #10317

Merged
merged 1 commit into from
Jan 1, 2017

Conversation

targos
Copy link
Member

@targos targos commented Dec 17, 2016

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

url

Description of change
  • Return a long from ParseNumber to prevent overflow for valid big numbers
  • Don't throw when there are more than 4 parts (it cannot be an IP
    address)
  • Correctly interpret the address and don't always throw when there are
    numbers > 255

Ref: https://url.spec.whatwg.org/#concept-ipv4-parser
Fixes: #10306

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Dec 17, 2016
@targos targos requested a review from jasnell December 17, 2016 13:23
@targos targos added the url Issues and PRs related to the legacy built-in url module. label Dec 17, 2016
@targos
Copy link
Member Author

targos commented Dec 17, 2016

cpplint is not happy:

src/node_url.cc:264:  Use int16/int64/etc, rather than the C type long  [runtime/int] [4]
src/node_url.cc:308:  Use int16/int64/etc, rather than the C type long  [runtime/int] [4]
src/node_url.cc:321:  Use int16/int64/etc, rather than the C type long  [runtime/int] [4]

How can I fix this?

@cjihrig
Copy link
Contributor

cjihrig commented Dec 17, 2016

@targos
Copy link
Member Author

targos commented Dec 17, 2016

I tried with int32_t and the result is different

@cjihrig
Copy link
Contributor

cjihrig commented Dec 17, 2016

If you're using long, you could try int64_t.

@mscdex
Copy link
Contributor

mscdex commented Dec 17, 2016

/cc @jasnell

@targos
Copy link
Member Author

targos commented Dec 17, 2016

@jasnell
Copy link
Member

jasnell commented Dec 17, 2016

I won't be able to review until Monday but as long as the fix adheres to the WHATWG spec then +1 and thank you!

@sam-github
Copy link
Contributor

Doesn't this imply that the WhatWG test suite is incomplete? Should the test changes be upstreamed to them?

jasnell
jasnell previously approved these changes Dec 19, 2016
@jasnell
Copy link
Member

jasnell commented Dec 19, 2016

@sam-github ... that is entirely possible.

@targos
Copy link
Member Author

targos commented Dec 19, 2016

@sam-github good idea. I opened a PR here: web-platform-tests/wpt#4365

goto end;
}
if (pointer - mark == 10) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@jasnell Just wondering if you remember what this condition was for? Maybe it was a mistake to remove it.

Copy link
Member

Choose a reason for hiding this comment

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

not off the top of my head... I'll be able to take a look in the next day or two. (sorry, company in town for the holiday is taking up quite a bit of my time this week)

@targos
Copy link
Member Author

targos commented Dec 20, 2016

My PR was merged and I updated our copy in the fixtures. Now the tests don't pass because of a spec change:

I'll work on it when I have some time

@targos
Copy link
Member Author

targos commented Dec 22, 2016

I had to add 3 other changes so that the updated tests can pass. This is ready to be reviewed again!

@targos
Copy link
Member Author

targos commented Dec 22, 2016

@targos targos changed the title url: make IPv4 parser more spec compliant url: make WHATWG URL implementation more spec compliant Dec 22, 2016
@targos
Copy link
Member Author

targos commented Dec 23, 2016

cc @nodejs/collaborators

@targos
Copy link
Member Author

targos commented Dec 30, 2016

Rebased. PTAL.

@targos
Copy link
Member Author

targos commented Dec 31, 2016

@targos
Copy link
Member Author

targos commented Dec 31, 2016

Should I squash all the commits together? If I don't, there will be commits with failing tests.

@benjamingr
Copy link
Member

I'm not familiar with the spec intimately, but I went through the changes and spec and they all LGTM

@gibfahn
Copy link
Member

gibfahn commented Dec 31, 2016

Should I squash all the commits together? If I don't, there will be commits with failing tests.

Definitely worth squashing so there aren't any commits with failing tests.

@jasnell
Copy link
Member

jasnell commented Jan 1, 2017

+1 to squashing

This patch contains the following changes:

url: make IPv4 parser more spec compliant

* Return int64_t from ParseNumber to prevent overflow for valid big numbers
* Don't throw when there are more than 4 parts (it cannot be an IP
address)
* Correctly interpret the address and don't always throw when there are
numbers > 255

Ref: https://url.spec.whatwg.org/#concept-ipv4-parser
Fixes: nodejs#10306

url: percent encode fragment to follow spec change

Ref: whatwg/url#150
Ref: whatwg/url@373dbed

url: fix URL#search setter

The check for empty string must be done before removing the leading '?'.

Ref: https://url.spec.whatwg.org/#dom-url-search

url: set port to null if an empty string is given

This is to follow a spec change.

Ref: whatwg/url#113

url: fix parsing of paths with Windows drive letter

test: update WHATWG URL test fixtures

PR-URL: nodejs#10317
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@targos targos merged commit db18dd8 into nodejs:master Jan 1, 2017
@targos targos added test Issues and PRs related to the tests. and removed dont-land-on-v7.x labels Jan 1, 2017
@targos targos deleted the fix-10306 branch January 1, 2017 10:03
@targos
Copy link
Member Author

targos commented Jan 1, 2017

Landed in db18dd8

@targos targos removed the test Issues and PRs related to the tests. label Jan 1, 2017
evanlucas pushed a commit that referenced this pull request Jan 3, 2017
This patch contains the following changes:

url: make IPv4 parser more spec compliant

* Return int64_t from ParseNumber to prevent overflow for valid big numbers
* Don't throw when there are more than 4 parts (it cannot be an IP
address)
* Correctly interpret the address and don't always throw when there are
numbers > 255

Ref: https://url.spec.whatwg.org/#concept-ipv4-parser
Fixes: #10306

url: percent encode fragment to follow spec change

Ref: whatwg/url#150
Ref: whatwg/url@373dbed

url: fix URL#search setter

The check for empty string must be done before removing the leading '?'.

Ref: https://url.spec.whatwg.org/#dom-url-search

url: set port to null if an empty string is given

This is to follow a spec change.

Ref: whatwg/url#113

url: fix parsing of paths with Windows drive letter

test: update WHATWG URL test fixtures

PR-URL: #10317
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
This patch contains the following changes:

url: make IPv4 parser more spec compliant

* Return int64_t from ParseNumber to prevent overflow for valid big numbers
* Don't throw when there are more than 4 parts (it cannot be an IP
address)
* Correctly interpret the address and don't always throw when there are
numbers > 255

Ref: https://url.spec.whatwg.org/#concept-ipv4-parser
Fixes: #10306

url: percent encode fragment to follow spec change

Ref: whatwg/url#150
Ref: whatwg/url@373dbed

url: fix URL#search setter

The check for empty string must be done before removing the leading '?'.

Ref: https://url.spec.whatwg.org/#dom-url-search

url: set port to null if an empty string is given

This is to follow a spec change.

Ref: whatwg/url#113

url: fix parsing of paths with Windows drive letter

test: update WHATWG URL test fixtures

PR-URL: #10317
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@joyeecheung joyeecheung added the whatwg-url Issues and PRs related to the WHATWG URL implementation. label Jan 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. url Issues and PRs related to the legacy built-in url module. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants