Skip to content

isIP 存在冗余代码 #1962

Closed
Closed
@381510688

Description

@381510688

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions