Skip to content

Commit

Permalink
Fix 08 parsed as decimal while 018 rejected.
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Apr 2, 2021
1 parent eb8b2c5 commit 50a0053
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/netmask.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ atob = (s) ->
i = 0
if s.length > 1 and s[i] == '0'
if s[i+1] == 'x' or s[i+1] == 'X'
i+=2
i += 2
base = 16
else if '0' <= s[i+1] and s[i+1] <= '7'
else if '0' <= s[i+1] and s[i+1] <= '9'
i++
base = 8
dmax = '7'
start = i
while s.length > 0
while i < s.length
if '0' <= s[i] and s[i] <= dmax
n = (n*base + (chr(s[i])-chr0)) >>> 0
else if base == 16
Expand Down
1 change: 1 addition & 0 deletions test/badnets.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ vows.describe('Invalid IP format')
'1.2.3.4 ': shouldFailWithError 'Invalid net'
'1 .2.3.4': shouldFailWithError 'Invalid net'
'018.0.0.0': shouldFailWithError 'Invalid net'
'08.0.0.0': shouldFailWithError 'Invalid net'
'0xfg.0.0.0': shouldFailWithError 'Invalid net'
.export(module)

Expand Down

0 comments on commit 50a0053

Please sign in to comment.