Skip to content

Cheshire lazy parsing lets some malformed JSON pass throughΒ #57

@rwilson

Description

@rwilson

Specifically, when the malformed JSON is in an array.

It's easily demonstrated in a repl:

user> (def bad-json (cheshire.core/parse-string "[{\"foo\": 1 2}]"))
#'user/bad-json
user> (type bad-json)
clojure.lang.LazySeq
user> (first bad-json)
JsonParseException Unexpected character ('2' (code 50)): was expecting comma to separate Object entries
 at [Source: (StringReader); line: 1, column: 13]  com.fasterxml.jackson.core.JsonParser._constructError (JsonParser.java:1798)

The JsonParseException isn't thrown until the lazy sequence is realized, which may not be until subsequent middleware or an endpoint.

Options could be:

  1. Lazy parsing has some benefits, leave it and document for clarity.
  2. Always or optionally realize body to catch the exception

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions