Skip to content

Commit 29b4533

Browse files
authored
Fix member accesses for non-decimal numeric literals (#377)
* Fix member accesses for non-decimal numeric literals e.g. 0x0.a should return undefined, not SyntaxError. * Remove ineffective non-decimal float parsing code and redundant checks on `is_float && radix != 10` (The code already wasn't doing anything because of the `is_float` check.)
1 parent 5797f2a commit 29b4533

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

quickjs.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10264,7 +10264,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
1026410264
to_digit((uint8_t)p[1]) < radix)) {
1026510265
p++;
1026610266
}
10267-
if (!(flags & ATOD_INT_ONLY)) {
10267+
if (!(flags & ATOD_INT_ONLY) && radix == 10) {
1026810268
if (*p == '.' && (p > p_start || to_digit((uint8_t)p[1]) < radix)) {
1026910269
is_float = TRUE;
1027010270
p++;
@@ -10274,9 +10274,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
1027410274
(*p == sep && to_digit((uint8_t)p[1]) < radix))
1027510275
p++;
1027610276
}
10277-
if (p > p_start &&
10278-
(((*p == 'e' || *p == 'E') && radix == 10) ||
10279-
((*p == 'p' || *p == 'P') && (radix == 2 || radix == 8 || radix == 16)))) {
10277+
if (p > p_start && (*p == 'e' || *p == 'E')) {
1028010278
const char *p1 = p + 1;
1028110279
is_float = TRUE;
1028210280
if (*p1 == '+') {
@@ -10317,11 +10315,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
1031710315
if (*p == 'n') {
1031810316
p++;
1031910317
atod_type = ATOD_TYPE_BIG_INT;
10320-
} else if (is_float && radix != 10) {
10321-
goto fail;
1032210318
}
10323-
} else if ((atod_type == ATOD_TYPE_FLOAT64) && is_float && radix != 10) {
10324-
goto fail;
1032510319
}
1032610320

1032710321
switch(atod_type) {

tests/test_language.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,16 @@ function test_reserved_names()
593593
test_name('static', SyntaxError);
594594
}
595595

596+
function test_number_literals()
597+
{
598+
assert(0.1.a, undefined);
599+
assert(0x1.a, undefined);
600+
assert(0b1.a, undefined);
601+
assert(01.a, undefined);
602+
assert(0o1.a, undefined);
603+
test_expr('0.a', SyntaxError);
604+
}
605+
596606
test_op1();
597607
test_cvt();
598608
test_eq();
@@ -613,3 +623,4 @@ test_function_length();
613623
test_argument_scope();
614624
test_function_expr_name();
615625
test_reserved_names();
626+
test_number_literals();

0 commit comments

Comments
 (0)