Giter Club home page Giter Club logo

Comments (6)

ibireme avatar ibireme commented on August 29, 2024

Thanks for your feedback~
I've fixed the incorrect error codes and added some test cases for them: 719b310

from yyjson.

lnkuiper avatar lnkuiper commented on August 29, 2024

Hi @ibireme ,

I have run into a similar issue again, this time with literals. If we read a JSON that has been cut off like this:

{"duck":tru

We get a YYJSON_READ_ERROR_LITERAL, but it should be YYJSON_READ_ERROR_UNEXPECTED_END. This is because the original pointer is not updated by the functions that read literals (e.g., true, false, inf, etc.). For example:

static_inline bool read_true(u8 **ptr, yyjson_val *val) {
    u8 *cur = *ptr;
    u8 **end = ptr;
    if (likely(byte_match_4(cur, "true"))) {
        val->tag = YYJSON_TYPE_BOOL | YYJSON_SUBTYPE_TRUE;
        *end = cur + 4;
        return true;
    }
    return false;
}

Should increment *ptr to where the error happens before returning false.

from yyjson.

ibireme avatar ibireme commented on August 29, 2024

@lnkuiper I think I understand your need now: a valid JSON truncated at any position should return exactly YYJSON_READ_ERROR_UNEXPECTED_END.

I just returned UNEXPECTED_END as a fallback before and didn't take care of this usage. So there is still some work to be done, especially to handle truncated unicode strings accurately.

from yyjson.

lnkuiper avatar lnkuiper commented on August 29, 2024

@ibireme exactly. I have a workaround that seems to work fine, so fixing this is not that important, but I thought I would report it anyway.

from yyjson.

ibireme avatar ibireme commented on August 29, 2024

I've fixed it by adding a new function that can detect whether a JSON that fails to parse is invalid, or valid but truncated: 8ffa6f5

I tested it with the JSONTestSuite dataset, and it seems to be working as expected.

from yyjson.

lnkuiper avatar lnkuiper commented on August 29, 2024

@ibireme This will help a lot with identifying problems when doing streaming JSON reads. Thank you so much!

from yyjson.

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.