mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
Description: Add endOfString check for JSON parse
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IACTDY?from=project-issue Signed-off-by: chenjx-huawei <chenjingxiang1@huawei.com> Change-Id: I407b26534cdd223c60b4fc6ec8b4ae77d2c2c713
This commit is contained in:
parent
41e67820ae
commit
2728135051
@ -153,6 +153,9 @@ protected:
|
||||
while (true) {
|
||||
SkipStartWhiteSpace();
|
||||
Tokens token = ParseToken();
|
||||
if (current_ > range_) {
|
||||
THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected end in JSON", JSTaggedValue::Exception());
|
||||
}
|
||||
switch (token) {
|
||||
case Tokens::OBJECT:
|
||||
if (EmptyObjectCheck()) {
|
||||
|
@ -35,3 +35,6 @@ Uf
|
||||
""
|
||||
Uf
|
||||
啕晦
|
||||
SyntaxError
|
||||
SyntaxError
|
||||
SyntaxError
|
||||
|
@ -83,3 +83,27 @@ print(JSON.parse('"\\u5555\\u6666"')); // utf8 -> utf16
|
||||
print(JSON.parse('["\\"\\"","中文"]')[0]); // utf16 -> utf8
|
||||
print(JSON.parse('["\\u0055\\u0066","中文"]')[0]); // utf16 -> utf8
|
||||
print(JSON.parse('["\\u5555\\u6666","中文"]')[0]); // utf16 -> utf16
|
||||
|
||||
const strData9 = `{"k1":"hello","k2":3}`;
|
||||
const strErr = strData9.substring(0, strData9.length - 2);
|
||||
try {
|
||||
JSON.parse(strErr);
|
||||
} catch (err) {
|
||||
print(err.name)
|
||||
}
|
||||
|
||||
const strData10 = `{"k1":"hello","k2": 3}`;
|
||||
const strErr2 = strData10.substring(0, strData10.length - 2);
|
||||
try {
|
||||
JSON.parse(strErr2);
|
||||
} catch (err) {
|
||||
print(err.name)
|
||||
}
|
||||
|
||||
const strData11 = `{"k1":"hello","k2":311111}`;
|
||||
const strErr3 = strData11.substring(0, strData11.length - 2);
|
||||
try {
|
||||
JSON.parse(strErr3);
|
||||
} catch (err) {
|
||||
print(err.name)
|
||||
}
|
Loading…
Reference in New Issue
Block a user