Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON parser rejects valid JSON with empty keys in objects #2836

Closed
badboy opened this issue May 24, 2024 · 1 comment · Fixed by #2962
Closed

JSON parser rejects valid JSON with empty keys in objects #2836

badboy opened this issue May 24, 2024 · 1 comment · Fixed by #2962
Assignees
Labels
bug Something isn't working
Milestone

Comments

@badboy
Copy link

badboy commented May 24, 2024

What is the current bug behavior?

JSON with empty keys ({ "": "value" }) is rejected with an error:

expecting an element; found empty element instead

Steps to reproduce

Run this request:

POST https://api.codapi.org/v1/exec
content-type: application/json
origin: https://codapi.org
{
    "sandbox": "python",
    "command": "run",
    "files": {
        "": "print('hello world')"
    }
}

fails with:

error: Parsing JSON
  --> example-request.hurl:8:9
   |
 8 |         "": "print('hello world')"
   |         ^ expecting an element; found empty element instead
   |

What is the expected correct behavior?

Request executes correctly, as empty keys in JSON are allowed.
This workaround works:

POST https://api.codapi.org/v1/exec
content-type: application/json
origin: https://codapi.org
```
{
    "sandbox": "python",
    "command": "run",
    "files": {
        "": "print('hello world')"
    }
}
```
$ hurl request.hurl
{"id":"python_run_f2057eb8","ok":true,"duration":273,"stdout":"hello world","stderr":""}

Execution context

❯ hurl --version
hurl 4.3.0 (aarch64-apple-darwin23.5.0) libcurl/8.7.1 OpenSSL/3.0.13 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libssh2/1.11.0 nghttp2/1.61.0
Features (libcurl):  alt-svc AsynchDNS brotli HSTS HTTP2 IDN IPv6 Largefile libz NTLM SPNEGO SSL TLS-SRP UnixSockets zstd
Features (built-in): brotli

Possible fixes

@badboy badboy added the bug Something isn't working label May 24, 2024
@fabricereix
Copy link
Collaborator

Thanks @badboy for reporting the bug.
An empty key is indeed valid JSON.
We will fix it for the next release.

@fabricereix fabricereix added this to the 5.0.0 milestone May 24, 2024
@fabricereix fabricereix linked a pull request Jun 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants