GithubHelp home page GithubHelp logo

Comments (5)

oreo-lp avatar oreo-lp commented on June 15, 2024

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

from json-tutorial.

oreo-lp avatar oreo-lp commented on June 15, 2024

再补充一下,如果测试用例中添加了这个测试用例,原来的处理逻辑会认为这是一个合法的数字,实际上这并不是一个合法的数字:
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.

Zhirui-Zhang avatar Zhirui-Zhang commented on June 15, 2024

再补充一下,如果测试用例中添加了这个测试用例,原来的处理逻辑会认为这是一个合法的数字,实际上这并不是一个合法的数字: 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.

1250890838 avatar 1250890838 commented on June 15, 2024

没问题啊,只解析了0

from json-tutorial.

1797818494 avatar 1797818494 commented on June 15, 2024

是的,我想错了

from json-tutorial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.