Skip to content

Fix member accesses for non-decimal numeric literals #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10264,7 +10264,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
to_digit((uint8_t)p[1]) < radix)) {
p++;
}
if (!(flags & ATOD_INT_ONLY)) {
if (!(flags & ATOD_INT_ONLY) && radix == 10) {
if (*p == '.' && (p > p_start || to_digit((uint8_t)p[1]) < radix)) {
is_float = TRUE;
p++;
Expand All @@ -10274,9 +10274,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
(*p == sep && to_digit((uint8_t)p[1]) < radix))
p++;
}
if (p > p_start &&
(((*p == 'e' || *p == 'E') && radix == 10) ||
((*p == 'p' || *p == 'P') && (radix == 2 || radix == 8 || radix == 16)))) {
if (p > p_start && (*p == 'e' || *p == 'E')) {
const char *p1 = p + 1;
is_float = TRUE;
if (*p1 == '+') {
Expand Down Expand Up @@ -10317,11 +10315,7 @@ static JSValue js_atof2(JSContext *ctx, const char *str, const char **pp,
if (*p == 'n') {
p++;
atod_type = ATOD_TYPE_BIG_INT;
} else if (is_float && radix != 10) {
goto fail;
}
} else if ((atod_type == ATOD_TYPE_FLOAT64) && is_float && radix != 10) {
goto fail;
}

switch(atod_type) {
Expand Down
11 changes: 11 additions & 0 deletions tests/test_language.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@ function test_reserved_names()
test_name('static', SyntaxError);
}

function test_number_literals()
{
assert(0.1.a, undefined);
assert(0x1.a, undefined);
assert(0b1.a, undefined);
assert(01.a, undefined);
assert(0o1.a, undefined);
test_expr('0.a', SyntaxError);
}

test_op1();
test_cvt();
test_eq();
Expand All @@ -613,3 +623,4 @@ test_function_length();
test_argument_scope();
test_function_expr_name();
test_reserved_names();
test_number_literals();