File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,12 @@ ip2long = (ip) ->
1010 if b .length is 0 or b .length > 4 then throw new Error (' Invalid IP' )
1111 for byte, i in b
1212 if byte and byte[0 ] == ' 0'
13- # make sure 0 prefixed bytes are parsed as octal
14- byte = parseInt (byte, 8 )
13+ if byte .length > 2 and (byte[1 ] == ' x' or byte[1 ] == ' x' )
14+ # make sure 0x prefixed bytes are parsed as hex
15+ byte = parseInt (byte, 16 )
16+ else
17+ # make sure 0 prefixed bytes are parsed as octal
18+ byte = parseInt (byte, 8 )
1519 else
1620 byte = parseInt (byte, 10 )
1721 if isNaN (byte) then throw new Error (" Invalid byte: #{ byte} " )
Original file line number Diff line number Diff line change @@ -57,10 +57,13 @@ vows.describe('Netmask contains IP')
5757 topic : -> new Netmask (' 31.0.0.0/8' )
5858 ' contains IP 31.5.5.5 ' : (block ) -> assert .ok block .contains (' 31.5.5.5' )
5959 ' does not contain IP 031.5.5.5 (25.5.5.5) ' : (block ) -> assert .ok not block .contains (' 031.5.5.5' )
60+ ' does not contain IP 0x31.5.5.5 (49.5.5.5) ' : (block ) -> assert .ok not block .contains (' 0x31.5.5.5' )
61+ ' does not contain IP 0X31.5.5.5 (49.5.5.5) ' : (block ) -> assert .ok not block .contains (' 0X31.5.5.5' )
6062 ' block 127.0.0.0/8' :
6163 topic : -> new Netmask (' 127.0.0.0/8' )
6264 ' contains IP 127.0.0.2 ' : (block ) -> assert .ok block .contains (' 127.0.0.2' )
6365 ' contains IP 0177.0.0.2 (127.0.0.2) ' : (block ) -> assert .ok block .contains (' 0177.0.0.2' )
66+ ' contains IP 0x7f.0.0.2 (127.0.0.2) ' : (block ) -> assert .ok block .contains (' 0x7f.0.0.2' )
6467 .export (module )
6568
6669vows .describe (' Netmask forEach' )
You can’t perform that action at this time.
0 commit comments