PaesslerAG / gval

Expression evaluation in golang
BSD 3-Clause "New" or "Revised" License
713 stars 83 forks source link

Fix json parsing bug #101

Open sivukhin opened 6 months ago

sivukhin commented 6 months ago

I ran govanish linter (it still in the WIP phase) against gval repo and it found that one error handling branch were eliminated by compiler:

2023/12/24 21:05:32 it seems like your code vanished from compiled binary: func=[parseJSONObject], file=[/home/sivukhin/code/gval/parse.go], line=[320], snippet:
    return nil, p.Expected("object", ':')
if p.Scan() != ':' {
    if err != nil {
        return nil, p.Expected("object", ':')
    }
}

Indeed, errcheck in this case is useless and actually prevent parsing from correct behaviour: rejecting invalid JSON structure.

This PR remove err check and always return error if p.Scan() return incorrect symbol.

Also, test Invalid json key:value structure for incorrect JSON structure were added (it were red before fix and became green after)