Skip to content

Commit 9bab173

Browse files
author
Nate Potter
committed
(MODULES-3980) Fix ipv4 regex validator
The current pattern for stdlib::compat::ipv4 is incorrect, and will return true for any four numbers separated with periods. This commit improves the regex to validate that the IP octets are between 1 and 255.
1 parent abb2c51 commit 9bab173

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

spec/aliases/ipv4_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
'nope',
2121
'77',
2222
'4.4.4',
23+
'9999.9999.9999.9999',
24+
'192.168.256.1',
2325
'2001:0db8:85a3:0000:0000:8a2e:0370:73342001:0db8:85a3:0000:0000:8a2e:0370:7334'
2426
].each do |value|
2527
describe value.inspect do

types/compat/ipv4.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Emulate the validate_ipv4_address and is_ipv4_address functions
2-
type Stdlib::Compat::Ipv4 = Pattern[/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/]
2+
type Stdlib::Compat::Ipv4 = Pattern[/^(([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]?){4}$/]

0 commit comments

Comments
 (0)