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

IPv4 number parser on "0x0a" #167

Closed
nlevitt opened this issue Dec 1, 2016 · 6 comments · Fixed by #171
Closed

IPv4 number parser on "0x0a" #167

nlevitt opened this issue Dec 1, 2016 · 6 comments · Fixed by #171

Comments

@nlevitt
Copy link

nlevitt commented Dec 1, 2016

https://url.spec.whatwg.org/#ipv4-number-parser

I think there's a bug in the spec here.

input="0x0a"

  1. Let R be 10.
    R = 10
  2. If input contains at least two code points and the first two code points are either "0x" or "0X", run these substeps:
    1. Set syntaxViolationFlag.
    2. Remove the first two code points from input.
      input = "0a"
    3. Set R to 16.
      R = 16
  3. If input is the empty string, return zero.
  4. Otherwise, if input contains at least two code points and the first code point is "0", run these substeps:
    we follow this code path
    1. Set syntaxViolationFlag.
    2. Remove the first code point from input.
      input = "a"
    3. Set R to 8.
      R = 8
  5. If input contains a code point that is not a radix-R digit, and return failure.
    return failure
  6. Return the mathematical integer value that is represented by input in radix-R notation, using ASCII hex digits for digits with values 0 through 15.
@nlevitt
Copy link
Author

nlevitt commented Dec 1, 2016

Ah and I should mention
https://github.com/w3c/web-platform-tests/blob/master/url/urltestdata.json#L2212

    "input": "http://192.0x00A80001",
    "href": "http://192.168.0.1/",

@nlevitt
Copy link
Author

nlevitt commented Dec 1, 2016

Swapping steps 3 and 4 fixes the problem.

@annevk
Copy link
Member

annevk commented Dec 9, 2016

Why did you mention the test?

annevk added a commit that referenced this issue Dec 9, 2016
This regressed in 1eab2ab in an
attempt to fix #50 for the second time… Not impressed.

Fixes #167.
@annevk
Copy link
Member

annevk commented Dec 9, 2016

In any event, created a PR to fix this. Would appreciate your review.

@nlevitt
Copy link
Author

nlevitt commented Dec 9, 2016

I mentioned the test because it has an ipv4 number that starts with "0x0" and it doesn't say the result should be failure, i.e. shows that this indeed a bug, assuming the test is correct.

@nlevitt
Copy link
Author

nlevitt commented Dec 9, 2016

Pull request looks good to me.

annevk added a commit that referenced this issue Dec 9, 2016
This regressed in 1eab2ab in an
attempt to fix #50 for the second time… Not impressed.

Fixes #167.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants