Skip to content

Commit f08a582

Browse files
committed
[js] Handle _ and unicode unary minus in string to number coercions
1 parent c001421 commit f08a582

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/vm/js/nqp-runtime/coercions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
exports.strToNum = function(str) {
2+
/* TODO - validate for correctness */
23
/* TODO - more converts more stuff */
34
if (str === 'NaN') return NaN;
45
if (str === 'Inf') return Infinity;
56
if (str === '-Inf') return -Infinity;
67
if (str === '+Inf') return Infinity;
7-
const parsed = parseFloat(str);
8+
const parsed = parseFloat(str.replace(/^\u2212/, '-').replace(/_/g, ''));
89
if (isNaN(parsed)) {
910
return 0;
1011
}

0 commit comments

Comments
 (0)