Skip to content

Improper parsing of JSON string "\\" #17

Closed

Description

@cmaloney

Currently the parser assumes if a '' is before a double quote, the double quote isn't the end of the string.

Note that there are more complicated cases like this (and their expansion) which need to be handled properly which probably will take more code to support properly: ("\"", "\") of arbitrary length. A reverse search which checks if the number of '' preceding the quote is even or odd would do it: https://github.com/nlohmann/json/blob/master/src/json.cc#L2050

Performance in backslash-heavy strings may suffer a lot though. Might be better to do a pure forward scan of the string counting backslashes as you go (Lots of memory access, but it should all be prefetched + L1 cached by current x86, x64 CPUs).

Activity

  1. added a commit that references this issue on Jan 9, 2015
  2. cmaloney commented on Jan 10, 2015

    @cmaloney
    Author

    Thanks for fixing this!

  3. added a commit that references this issue on May 7, 2021
  4. added a commit that references this issue on Sep 26, 2024
  5. added a commit that references this issue on Nov 13, 2025
  6. added a commit that references this issue on Dec 16, 2025
  7. added a commit that references this issue on Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions