Skip to content
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

tutorial2中非法的情况是不是没判断完全 #231

Open
1797818494 opened this issue Oct 1, 2022 · 5 comments
Open

tutorial2中非法的情况是不是没判断完全 #231

1797818494 opened this issue Oct 1, 2022 · 5 comments

Comments

@1797818494
Copy link

如果我把一个数写成0k不也是返回的是lept_number

@oreo-lp
Copy link

oreo-lp commented Oct 18, 2022

lept_parse_number()函数的其中一个判断应该改成这样吧:
if (*p == '0'){ p++; if (*p != '\0' && *p != '.' ) return LEPT_PARSE_INVALID_VALUE; }

@oreo-lp
Copy link

oreo-lp commented Oct 18, 2022

再补充一下,如果测试用例中添加了这个测试用例,原来的处理逻辑会认为这是一个合法的数字,实际上这并不是一个合法的数字:
TEST_ERROR(LEPT_PARSE_INVALID_VALUE, "-1E-10k");
所以,应该需要将判断语句修改成这样:
if (*p == 'e' || *p == 'E') { p++; if (*p == '+' || *p == '-') p++; if (!ISDIGIT(*p)) return LEPT_PARSE_INVALID_VALUE; for (p++; ISDIGIT(*p); p++); if(*p != '\0'){ return LEPT_PARSE_INVALID_VALUE; } }

@Zhirui-Zhang
Copy link

再补充一下,如果测试用例中添加了这个测试用例,原来的处理逻辑会认为这是一个合法的数字,实际上这并不是一个合法的数字: TEST_ERROR(LEPT_PARSE_INVALID_VALUE, "-1E-10k"); 所以,应该需要将判断语句修改成这样: if (*p == 'e' || *p == 'E') { p++; if (*p == '+' || *p == '-') p++; if (!ISDIGIT(*p)) return LEPT_PARSE_INVALID_VALUE; for (p++; ISDIGIT(*p); p++); if(*p != '\0'){ return LEPT_PARSE_INVALID_VALUE; } }

你这个测试用例应该改为:
TEST_PARSE_ERROR(LEPT_PARSE_ROOT_NOT_SINGULAR, "-1E-10k");,是可以通过测试的(个人测试成功),lept_parse_number函数解析到k处退出,此时v->u.n = strtod()结果为-1E-10。到最外层的if (*c.json != '\0')判断为true,最后返回 LEPT_PARSE_ROOT_NOT_SINGULAR,综上,我个人认为作者代码应该不需要修改

@1250890838
Copy link

没问题啊,只解析了0

@1797818494
Copy link
Author

是的,我想错了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants