Open sebkun opened 13 years ago
If you don't want $.deparam
to attempt to coerce strings into numbers, you can simply not specify the coerce
argument. Have you tried that?
Good point, although then it doesn't convert other values and in my use case the loss of precision for large numbers (random 64-bit IDs) was undesirable.
Javascript does not support numbers > 2^53, you should keep them as strings in that case.
Part of the deParam() code tries to parse numeric values into Javascript numbers. However, since javascript stores all numbers as doubles, any number larger than around 2^53 will suffer a loss of precision when converted.
E.g.: var longNum = "123456789012346578901234567980"; var urlStr = "http://www.example.com/?key=" + longNum; var url = $.url.parse(urlStr); alert(url.params['key']); // 1.2345678901234658e+29
In my code I worked around this by changing: val = val && !isNaN(val) ? +val // number to val = val && !isNaN(val) && val < 0x20000000000000 ? +val // number