Skip to content

Commit 50a0053

Browse files
committed
Fix 08 parsed as decimal while 018 rejected.
1 parent eb8b2c5 commit 50a0053

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/netmask.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ atob = (s) ->
5757
i = 0
5858
if s.length > 1 and s[i] == '0'
5959
if s[i+1] == 'x' or s[i+1] == 'X'
60-
i+=2
60+
i += 2
6161
base = 16
62-
else if '0' <= s[i+1] and s[i+1] <= '7'
62+
else if '0' <= s[i+1] and s[i+1] <= '9'
6363
i++
6464
base = 8
6565
dmax = '7'
6666
start = i
67-
while s.length > 0
67+
while i < s.length
6868
if '0' <= s[i] and s[i] <= dmax
6969
n = (n*base + (chr(s[i])-chr0)) >>> 0
7070
else if base == 16

test/badnets.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ vows.describe('Invalid IP format')
4242
'1.2.3.4 ': shouldFailWithError 'Invalid net'
4343
'1 .2.3.4': shouldFailWithError 'Invalid net'
4444
'018.0.0.0': shouldFailWithError 'Invalid net'
45+
'08.0.0.0': shouldFailWithError 'Invalid net'
4546
'0xfg.0.0.0': shouldFailWithError 'Invalid net'
4647
.export(module)
4748

0 commit comments

Comments
 (0)