-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
fixed wrongly approved zero padded ip 4 #490
Conversation
Thanks. |
fixed wrongly approved zero padded ip 4
Btw, this still leaves |
I'm not sure how complex you want this regex to be (since in general regex might have their own security issues) Also I'm not sure if everyone considers leading zeros to be completely invalid so this might better go with a feature flag or in a major release. |
I agree that leading zeroes are not necessarily a problem (and yes, sorry, didn’t think of things like |
how about IPv4 is made out of maximum three digits subset it makes sense not to allow any padding to anything more than that |
Yeah, I do get why one may want to forbid leading zeroes, and I’m not disagreeing in any way with that being a good idea! :) I’m just saying the way it’s implemented now is inconsistent, and inconsistency is usually something you want to avoid (for obvious reasons). |
Ah, I guess I didn't understand what you meant. |
Exactly, I’m a little afraid someone will trip over the difference between handling |
Agree. |
Here is an implementation suggestion. if (str.length < 7 || str.length > 15) {
return false;
}
var parts = str.split('.');
var i;
var num;
if (parts.length !== 4) {
return false;
}
for(i = 0; i < 4; i += 1) {
num = parseInt(parts[i], 10);
if (!(num >= 0 && num <= 255 && num.toString() === parts[i])) {
return false;
}
}
return true; |
BTW, I checked many js libraries that validate ips (joi, ip, ip-address) |
+1 on your implementation! I’d suggest you add a comment for explaining where the “magic” constants |
No description provided.