whitequark / ipaddr.js

IP address manipulation library in JavaScript
MIT License
576 stars 92 forks source link

IP parsed in a wrong way. #132

Closed EitanK96 closed 4 years ago

EitanK96 commented 4 years ago

hey,

i have written unit tests to a function that uses ipaddr.js and i found some weird behaviour.

const ipaddr = require('ipaddr.js')
ipaddr.parse('14.048.2.7')

for an input of '14.048.2.7' it should return that this IP is Invalid. because from the parser point of view 8 is not in the octal range and that is why it is invalid. what it actually returns is a parsed ip which looks like this '14.4.2.7'.

i think that the issue lies in this part of the code:

    function parseIntAuto (string) {
        if (string[0] === '0' && string[1] !== 'x') {
            return parseInt(string, 8);
        } else {
            return parseInt(string);
        }
    }

maybe there should be a validation that the digits are in the octal range

whitequark commented 4 years ago

Thanks. Do you think you could make a PR fixing this?

EitanK96 commented 4 years ago

Thanks. Do you think you could make a PR fixing this?

will do as soon as i have more free time at work :)