Skip to content

Commit

Permalink
fix(isIP): wrong IP address validation (#1211)
Browse files Browse the repository at this point in the history
* Bugfix - Wrong IP address validation
#1209

* Add tests for IPv4

Co-authored-by: Bar <[email protected]>
  • Loading branch information
molaga and Bar authored Feb 11, 2020
1 parent a87165a commit c109ace
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion es/lib/isIP.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import assertString from './util/assertString';
to the 5th link, and "interface10" belongs to the 10th organization.
* * */

var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
var ipv6Block = /^[0-9A-F]{1,4}$/i;
export default function isIP(str) {
var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
Expand Down
2 changes: 1 addition & 1 deletion lib/isIP.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
to the 5th link, and "interface10" belongs to the 10th organization.
* * */
var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
var ipv6Block = /^[0-9A-F]{1,4}$/i;

function isIP(str) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isIP.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import assertString from './util/assertString';
where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
to the 5th link, and "interface10" belongs to the 10th organization.
* * */
const ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
const ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
const ipv6Block = /^[0-9A-F]{1,4}$/i;

export default function isIP(str, version = '') {
Expand Down
5 changes: 5 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,16 @@ describe('Validators', () => {
'0.0.0.0',
'255.255.255.255',
'1.2.3.4',
'255.0.0.1',
'0.0.1.1',
],
invalid: [
'::1',
'2001:db8:0000:1:1:1:1:1',
'::ffff:127.0.0.1',
'137.132.10.01',
'0.256.0.256',
'255.256.255.256',
],
});
test({
Expand Down

0 comments on commit c109ace

Please sign in to comment.