Skip to content

url: make WHATWG URL implementation more spec compliant - #10317

Merged
targos merged 1 commit into
nodejs:masterfrom
targos:fix-10306
Jan 1, 2017
Merged

url: make WHATWG URL implementation more spec compliant#10317
targos merged 1 commit into
nodejs:masterfrom
targos:fix-10306

Conversation

@targos

@targostargos commented Dec 17, 2016

Copy link
Copy Markdown
Member
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-botnodejs-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 jasnellDecember 17, 2016 13:23
@targostargos added the url Issues and PRs related to the legacy built-in url module. label Dec 17, 2016
@targos

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
Contributor

@targos

Copy link
Copy Markdown
MemberAuthor

I tried with int32_t and the result is different

@cjihrig

Copy link
Copy Markdown
Contributor

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

@mscdex

Copy link
Copy Markdown
Contributor

/cc @jasnell

@targos

targos commented Dec 17, 2016

Copy link
Copy Markdown
MemberAuthor

@jasnell

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

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

@targos

Copy link
Copy Markdown
MemberAuthor

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

Comment threadsrc/node_url.cc Outdated

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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

@targos

Copy link
Copy Markdown
MemberAuthor

@targostargos changed the title url: make IPv4 parser more spec complianturl: make WHATWG URL implementation more spec compliantDec 22, 2016
@targos

Copy link
Copy Markdown
MemberAuthor

cc @nodejs/collaborators

@targos

Copy link
Copy Markdown
MemberAuthor

Rebased. PTAL.

@targos

Copy link
Copy Markdown
MemberAuthor

@targos

Copy link
Copy Markdown
MemberAuthor

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

@benjamingr

Copy link
Copy Markdown
Member

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

@gibfahn

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

+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-parserFixes: 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:masterJan 1, 2017
@targostargos 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
Copy Markdown
MemberAuthor

Landed in db18dd8

@targostargos removed the test Issues and PRs related to the tests. label Jan 1, 2017
@evanlucasevanlucas mentioned this pull request Jan 3, 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-parserFixes: #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-parserFixes: #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>
@joyeecheungjoyeecheung added the whatwg-url Issues and PRs related to the WHATWG URL implementation. label Jan 5, 2017
Sign up for freeto 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++.urlIssues and PRs related to the legacy built-in url module.whatwg-urlIssues and PRs related to the WHATWG URL implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@targos@cjihrig@mscdex@jasnell@sam-github@benjamingr@gibfahn@joyeecheung@nodejs-github-bot