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

isIP 存在冗余代码 #1962

Closed
381510688 opened this issue May 4, 2022 · 1 comment · Fixed by #1969
Closed

isIP 存在冗余代码 #1962

381510688 opened this issue May 4, 2022 · 1 comment · Fixed by #1969
Labels

Comments

@381510688
Copy link

381510688 commented May 4, 2022

Describe the bug
A clear and concise description of what the bug is.

https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js#L57

const parts = str.split('.').sort((a, b) => a - b);
return parts[3] <= 255;

请教一下,这两句代码的意义?
上面正则已经严格控制,一定是数字且会小于255

const IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
const IPv4AddressFormat = `(${IPv4SegmentFormat}[.]){3}${IPv4SegmentFormat}`;
const IPv4AddressRegExp = new RegExp(`^${IPv4AddressFormat}$`);

Examples
If applicable, add screenshots to help explain your problem.

Additional context
Validator.js version:
Node.js version:
OS platform: [windows, linux, macOS, etc]

UnKnoWn-Consortium added a commit to UnKnoWn-Consortium/validator.js that referenced this issue May 16, 2022
UnKnoWn-Consortium added a commit to UnKnoWn-Consortium/validator.js that referenced this issue May 16, 2022
UnKnoWn-Consortium added a commit to UnKnoWn-Consortium/validator.js that referenced this issue May 16, 2022
UnKnoWn-Consortium added a commit to UnKnoWn-Consortium/validator.js that referenced this issue May 16, 2022
@UnKnoWn-Consortium
Copy link
Contributor

Indeed the two statements are redundant.

From git blame, they appears to be leftover from before the regular expression rewrite that occurred 13 months ago. I have created a pull request #1969 to rectify it.

If you like you can create yours and I will retract mine.

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

Successfully merging a pull request may close this issue.

2 participants