Skip to content

Leading whitespaces lead to incorrect results (jsonparser.ArrayEach) #150

Description

@coxx
data := []byte(`[1, 2, 3]`)
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
    fmt.Println(string(value))
})

returns

1
2
3

but

data := []byte(`    [1, 2, 3]`)
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
    fmt.Println(string(value))
})

returns

[1, 2, 3]

Activity

  1. sauerbraten commented on Jan 22, 2021

    @sauerbraten

    Similarly, Delete seems to "silently" fail when there is leading whitespace:
    This works: https://play.golang.org/p/Jub6y91ObT0
    This doesn't: https://play.golang.org/p/FLM_k3GU6nc

  2. buger commented on Jan 22, 2021

    @buger
    Owner

    Should be a pretty simple fix, e.g. just skip spaces at the start.
    PRs are welcomed :)

  3. buger commented on Mar 19, 2021

    @buger
    Owner

    Fixed now, thanks @daria-kay!

  4. reopened this on Mar 21, 2021
  5. buger commented on Mar 21, 2021

    @buger
    Owner

    Have to re-open because of bug found by OSS-Fuzz. See attached PR for error details.

  6. kadukm commented on May 11, 2021

    @kadukm

    OSS-Fuzz bug is solved by #227. Can issue be closed?

  7. buger commented on Jul 28, 2026

    @buger
    Owner

    Fixed — ArrayEach now handles leading whitespace correctly. Additionally, v1.3.0 hardened ArrayEach to return a clean error (no spurious callback) when the root value is not an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions