mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-22 13:48:11 +08:00
Fix non-ASCII strings in JS_NewAtomLen
This commit is contained in:
parent
36911f0d3a
commit
b049cf0704
@ -2964,11 +2964,16 @@ JSAtom JS_NewAtomLen(JSContext *ctx, const char *str, size_t len)
|
|||||||
JSValue val;
|
JSValue val;
|
||||||
|
|
||||||
if (len == 0 || !is_digit(*str)) {
|
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);
|
JSAtom atom = __JS_FindAtom(ctx->rt, str, len, JS_ATOM_TYPE_STRING);
|
||||||
if (atom)
|
if (atom)
|
||||||
return atom;
|
return atom;
|
||||||
}
|
}
|
||||||
|
slow_path:
|
||||||
val = JS_NewStringLen(ctx, str, len);
|
val = JS_NewStringLen(ctx, str, len);
|
||||||
if (JS_IsException(val))
|
if (JS_IsException(val))
|
||||||
return JS_ATOM_NULL;
|
return JS_ATOM_NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user