|
The parseInt(string, radix) function takes a radix argument and it is strongly encouraged that one is always specified. A numeric string beginning with a leading zero may be interpreted as octal depending on what JS engine is being used and its version.
With MongoDB 3.0.6 (uses v8),
> parseInt('08')
|
0
|
> parseInt('08', 10)
|
8
|
> parseInt('0128')
|
10
|
> parseInt('0128', 10)
|
128
|
With MongoDB 3.1.7 (uses SpiderMonkey, ES5 compliant),
> parseInt('08')
|
8
|
> parseInt('08', 10)
|
8
|
> parseInt('0128')
|
128
|
> parseInt('0128', 10)
|
128
|
If the input string begins with "0", radix is eight (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.
See the documentation on parseInt() for more details.
Closing this ticket as "works as designed".
|