Skip to content

Commit

Permalink
Spec update: disallow invalid IPv4 in the IPv6 parser
Browse files Browse the repository at this point in the history
This matches whatwg/url#196.
  • Loading branch information
domenic authored Jan 12, 2017
1 parent 2556e46 commit b1a09a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe

## Current Status

whatwg-url is currently up to date with the URL spec up to commit [fbff68](https://github.com/whatwg/url/tree/fbff6834a8a03576261f777d0e0afea5c1bc5a09).
whatwg-url is currently up to date with the URL spec up to commit [a7ae1b](https://github.com/whatwg/url/tree/a7ae1b846b91d564229faeaafdd28cb7451faa1d).

## API

Expand Down
3 changes: 1 addition & 2 deletions scripts/get-latest-platform-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ const fs = require("fs");
const request = require("request");

// Pin to specific version, reflecting the spec version in the readme.
// At the moment we are pinned to a branch.
//
// To get the latest commit:
// 1. Go to https://github.com/w3c/web-platform-tests/tree/master/url
// 2. Press "y" on your keyboard to get a permalink
// 3. Copy the commit hash
const commitHash = "1e1e80441b8d6a60f836de4005dba25698ecfe4a";
const commitHash = "82173128ef6f536e5faaafc29eecc521380f81ae";

const sourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/urltestdata.json`;
const setterSourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/setters_tests.json`;
Expand Down
26 changes: 15 additions & 11 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,19 @@ function parseIPv6(input) {
if (ipv4 && piecePtr > 6) {
return failure;
} else if (input[pointer] !== undefined) {
let dotsSeen = 0;
let numbersSeen = 0;

while (input[pointer] !== undefined) {
let value = null;

if (numbersSeen > 0) {
if (input[pointer] === p(".") && numbersSeen < 4) {
++pointer;
} else {
return failure;
}
}

if (!isASCIIDigit(input[pointer])) {
return failure;
}
Expand All @@ -301,22 +310,17 @@ function parseIPv6(input) {
}
}

if (dotsSeen < 3 && input[pointer] !== p(".")) {
return failure;
}
ip[piecePtr] = ip[piecePtr] * 0x100 + value;
if (dotsSeen === 1 || dotsSeen === 3) {
++piecePtr;
}

if (input[pointer] !== undefined) {
++pointer;
++numbersSeen;

if (numbersSeen === 2 || numbersSeen === 4) {
++piecePtr;
}

if (dotsSeen === 3 && input[pointer] !== undefined) {
if (input[pointer] === undefined && numbersSeen !== 4) {
return failure;
}
++dotsSeen;
}
}

Expand Down

0 comments on commit b1a09a3

Please sign in to comment.