Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions library/src/actions/ip/ip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ describe('ip', () => {
'FE80:0000:0000:0000:0202:B3FF:FE1E:8329',
'fe80::1ff:fe23:4567:890a',
'2001:db8:85a3:8d3:1319:8a2e:370:7348',
'fe80::1%eth0',
'FE80::1%ETH0',
'::FFFF:192.0.2.128',
]);
});
});
Expand Down Expand Up @@ -122,5 +125,12 @@ describe('ip', () => {
'test:test:test:test:test:test:test:test',
]);
});
test('for non ASCII chars', () => {
expectActionIssue(action, baseIssue, [
'fe80::1%é',
'fe80::1%\u017F', // U+017F LATIN SMALL LETTER LONG S
'fe80::1%\u212A', // U+212A KELVIN SIGN
]);
});
});
});
11 changes: 11 additions & 0 deletions library/src/actions/ipv6/ipv6.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ describe('ipv6', () => {
'FE80:0000:0000:0000:0202:B3FF:FE1E:8329',
'fe80::1ff:fe23:4567:890a',
'2001:db8:85a3:8d3:1319:8a2e:370:7348',
'fe80::1%eth0',
'FE80::1%ETH0',
'::FFFF:192.0.2.128',
]);
});
});
Expand Down Expand Up @@ -101,6 +104,14 @@ describe('ipv6', () => {
]);
});

test('for non ASCII chars', () => {
expectActionIssue(action, baseIssue, [
'fe80::1%é',
'fe80::1%\u017F', // U+017F LATIN SMALL LETTER LONG S
'fe80::1%\u212A', // U+212A KELVIN SIGN
]);
});

test('for IPv4 address', () => {
expectActionIssue(action, baseIssue, [
'192.168.1.1',
Expand Down
10 changes: 8 additions & 2 deletions library/src/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,21 @@ export const IPV4_REGEX: RegExp =

/**
* [IPv6](https://en.wikipedia.org/wiki/IPv6) regex.
*
* Hint: We decided against the `i` flag to avoid matching non-ASCII characters.
*/
export const IPV6_REGEX: RegExp =
/^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,7}:|(?:[\da-f]{1,4}:){1,6}:[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,5}(?::[\da-f]{1,4}){1,2}|(?:[\da-f]{1,4}:){1,4}(?::[\da-f]{1,4}){1,3}|(?:[\da-f]{1,4}:){1,3}(?::[\da-f]{1,4}){1,4}|(?:[\da-f]{1,4}:){1,2}(?::[\da-f]{1,4}){1,5}|[\da-f]{1,4}:(?::[\da-f]{1,4}){1,6}|:(?:(?::[\da-f]{1,4}){1,7}|:)|fe80:(?::[\da-f]{0,4}){0,4}%[\da-z]+|::(?:f{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-f]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/iu;
// eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive
/^(?:(?:[\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}|(?:[\da-fA-F]{1,4}:){1,7}:|(?:[\da-fA-F]{1,4}:){1,6}:[\da-fA-F]{1,4}|(?:[\da-fA-F]{1,4}:){1,5}(?::[\da-fA-F]{1,4}){1,2}|(?:[\da-fA-F]{1,4}:){1,4}(?::[\da-fA-F]{1,4}){1,3}|(?:[\da-fA-F]{1,4}:){1,3}(?::[\da-fA-F]{1,4}){1,4}|(?:[\da-fA-F]{1,4}:){1,2}(?::[\da-fA-F]{1,4}){1,5}|[\da-fA-F]{1,4}:(?::[\da-fA-F]{1,4}){1,6}|:(?:(?::[\da-fA-F]{1,4}){1,7}|:)|[fF][eE]80:(?::[\da-fA-F]{0,4}){0,4}%[\da-zA-Z]+|::(?:[fF]{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/u;

/**
* [IP](https://en.wikipedia.org/wiki/IP_address) regex.
*
* Hint: We decided against the `i` flag to avoid matching non-ASCII characters.
*/
export const IP_REGEX: RegExp =
/^(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])(?:\.(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])){3}$|^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,7}:|(?:[\da-f]{1,4}:){1,6}:[\da-f]{1,4}|(?:[\da-f]{1,4}:){1,5}(?::[\da-f]{1,4}){1,2}|(?:[\da-f]{1,4}:){1,4}(?::[\da-f]{1,4}){1,3}|(?:[\da-f]{1,4}:){1,3}(?::[\da-f]{1,4}){1,4}|(?:[\da-f]{1,4}:){1,2}(?::[\da-f]{1,4}){1,5}|[\da-f]{1,4}:(?::[\da-f]{1,4}){1,6}|:(?:(?::[\da-f]{1,4}){1,7}|:)|fe80:(?::[\da-f]{0,4}){0,4}%[\da-z]+|::(?:f{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-f]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/iu;
// eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive
/^(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])(?:\.(?:(?:[1-9]|1\d|2[0-4])?\d|25[0-5])){3}$|^(?:(?:[\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}|(?:[\da-fA-F]{1,4}:){1,7}:|(?:[\da-fA-F]{1,4}:){1,6}:[\da-fA-F]{1,4}|(?:[\da-fA-F]{1,4}:){1,5}(?::[\da-fA-F]{1,4}){1,2}|(?:[\da-fA-F]{1,4}:){1,4}(?::[\da-fA-F]{1,4}){1,3}|(?:[\da-fA-F]{1,4}:){1,3}(?::[\da-fA-F]{1,4}){1,4}|(?:[\da-fA-F]{1,4}:){1,2}(?::[\da-fA-F]{1,4}){1,5}|[\da-fA-F]{1,4}:(?::[\da-fA-F]{1,4}){1,6}|:(?:(?::[\da-fA-F]{1,4}){1,7}|:)|[fF][eE]80:(?::[\da-fA-F]{0,4}){0,4}%[\da-zA-Z]+|::(?:[fF]{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d)|(?:[\da-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?\d)?\d)\.){3}(?:25[0-5]|(?:2[0-4]|1?\d)?\d))$/u;

/**
* [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date regex.
Expand Down