Comments (5)
lept_parse_number()函数的其中一个判断应该改成这样吧:
if (*p == '0'){ p++; if (*p != '\0' && *p != '.' ) return LEPT_PARSE_INVALID_VALUE; }
from json-tutorial.
再补充一下,如果测试用例中添加了这个测试用例,原来的处理逻辑会认为这是一个合法的数字,实际上这并不是一个合法的数字:
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; } }
from json-tutorial.
再补充一下,如果测试用例中添加了这个测试用例,原来的处理逻辑会认为这是一个合法的数字,实际上这并不是一个合法的数字:
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
,综上,我个人认为作者代码应该不需要修改
from json-tutorial.
没问题啊,只解析了0
from json-tutorial.
是的,我想错了
from json-tutorial.
Related Issues (20)
- Tutorial3中关于首次调用lept_free()函数的问题
- 关于tutorial02的一张图 HOT 1
- 关于生成字符串的问题
- 关于生成器对\u字符的处理
- 不是很理解判断字符tutorial02中连续判断数字的代码 (p++; ISDIGIT(*p); p++); HOT 2
- 关于Tutorial04中将Unicode字符转换为UTF-8存储的lept_encode_utf8的写法 HOT 1
- about tutorial07 function—lept_stringify_string. why not add ' \" ' because it's the begin or end mark for a string HOT 3
- 毛遂自荐一下 HOT 1
- 关于使用宏而不是内联函数的问题
- 关于tutorial2对含有前导零数字处理的问题 HOT 1
- 指数解析出现问题, HOT 2
- C++ 版本(含详细注解~)
- https://github.com/Tencent/rapidjson
- 解析字符串时,代理对不是针对 utf-16 才有的吗,这里是解析utf-8 的编解码,也需要处理代理对? HOT 2
- 这里的为啥右移 HOT 1
- 关于第九章
- 'errno.h' 不是ANSI C的头文件 HOT 1
- 关于 tutorial2 中的这个 “0123”这个字符串的解析 HOT 1
- 补充一段JSON number解析代码
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-tutorial.