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
Support prefix #399
Support prefix #399
Conversation
I see two small issues with this:
|
Regarding my first point: The RFC 3493 says that |
Agreed. So what changes would you like to see? Just case insensitivity for the prefix? Or a split on ::\d+.? Because ::ffff (and any of the examples you gave me) do validate this way. I also get the ignoring bit when it comes to specifically specifying an IP address... But should it? It' a valid IP. |
I’d say case insensitivity + rather testing as IPv6 addresses than as IPv4 addresses. For example, one could insert something like if (/^::ffff:/i.test(str) && validator.isIP(str.substr(7), 4))
return true; after validator.js:274 (i.e. |
Splitting on ::\d+.? seems to also work. Both sides need to match before it returns true. One for ipv6 and one for ipv4... |
Hm, yeah. You can do that, but keep in mind that the left side should have 6 blocks rather than the usual 8… |
Small test:
More readable var v = require('validator'),
ipParts = '::ffff:127.0.0.1'.split(':'),
ipv4 = ipParts.pop(),
ipv6 = ipParts.join(':');
console.log(v.isIP(ipv4) && v.isIP(ipv6));
// true this works with the current system, without any of my changes. |
Still, this approach treats |
I pushed a suggestion for solving this to addaleax/ipv4-mapped-ipv6-addr, you can take merge it into this PR or ignore it if you’re unhappy with it |
Are you sure 0:0:0:0:0:ffff:127.0.0.1 is valid? Because the number of blocks don't match with the transition structure. It would for a full-out ipv6, that's true, but I don't believe it's valid. |
> var reg = new RegExp('(([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))');
> reg.test('0:0:0:0:0:ffff:127.0.0.1');
false
> reg.test('::ffff:127.0.0.1');
true |
Well, given that I can use addresses of the format
|
Nobody is going to write it like that. But you're right, they can. Either way, none of my solutions seem to fit. |
Don’t get me wrong – I’m not saying that |
I don't mind. |
https://en.wikipedia.org/wiki/IPv6_address#Transition_from_IPv4
Some issues arose in Waterline, which uses anchor. which uses validator.js. ::ffff:127.0.0.1 is a prefixed IPv4. I found this on StackOverflow.