Skip to content

Commit

Permalink
Fix non-ASCII strings in JS_NewAtomLen
Browse files Browse the repository at this point in the history
  • Loading branch information
Emill committed Jun 9, 2024
1 parent 36911f0 commit b049cf0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2964,11 +2964,16 @@ JSAtom JS_NewAtomLen(JSContext *ctx, const char *str, size_t len)
JSValue val;

if (len == 0 || !is_digit(*str)) {
// XXX: this will not work if UTF-8 encoded str contains non ASCII bytes
size_t i;
for(i = 0; i < len; i++) {
if ((uint8_t)str[i] >= 0x80)
goto slow_path;
}
JSAtom atom = __JS_FindAtom(ctx->rt, str, len, JS_ATOM_TYPE_STRING);
if (atom)
return atom;
}
slow_path:
val = JS_NewStringLen(ctx, str, len);
if (JS_IsException(val))
return JS_ATOM_NULL;
Expand Down

0 comments on commit b049cf0

Please sign in to comment.