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

Invalid JSON input on handlebars is not reported properly. #2546

Closed
dirkbolte opened this issue Dec 22, 2023 · 3 comments
Closed

Invalid JSON input on handlebars is not reported properly. #2546

dirkbolte opened this issue Dec 22, 2023 · 3 comments
Labels

Comments

@dirkbolte
Copy link
Contributor

dirkbolte commented Dec 22, 2023

Proposal

See thread https://wiremock-community.slack.com/archives/C03N1E6HFPY/p1703250590706619 .

When an input JSON is empty, this results in a HandlebarsException, which is converted into the following response.

{
    "cause1": "java.lang.IllegalArgumentException: json string can not be null or empty",
    "servlet": "com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet-4af6839c",
    "cause0": "com.github.jknack.handlebars.HandlebarsException: inline@35c3c400:1:2: java.lang.IllegalArgumentException: json string can not be null or empty\n    inline@35c3c400:1:2",
    "message": "com.github.jknack.handlebars.HandlebarsException: inline@35c3c400:1:2: java.lang.IllegalArgumentException: json string can not be null or empty\n    inline@35c3c400:1:2",
    "url": "/test",
    "status": "500"
}

I would have expected

to have caught the issue but it seems like the actual exception is different (breakpoint isn't hit).

Reproduction steps

  • Create response templating which uses handlebars (e.g. a POST)
  • add handlebars code: {{jsonPath (defaultIfEmpty request.body '{}') '$.doesNotExist' }}
  • do a request without a body

Expected behavior:

  • handleError is executed.

Actual:

  • the error is encoded in the response.

References

See thread https://wiremock-community.slack.com/archives/C03N1E6HFPY/p1703250590706619 .

@dirkbolte dirkbolte added the bug label Dec 22, 2023
@dirkbolte
Copy link
Contributor Author

Found that the code already had some precautions for a null body - would suggest to use the same approach for empty string.

dirkbolte added a commit to dirkbolte/wiremock that referenced this issue Jan 1, 2024
Instead of having `jsonpath` in handlebars throwing an `IllegalArgumentException`,
empty bodies are handled the same way as `null` bodies: as empty string
tomakehurst pushed a commit that referenced this issue Jan 15, 2024
Instead of having `jsonpath` in handlebars throwing an `IllegalArgumentException`,
empty bodies are handled the same way as `null` bodies: as empty string
@G-Basak
Copy link
Contributor

G-Basak commented Jan 17, 2024

@dirkbolte Is this issue good to close?

@dirkbolte
Copy link
Contributor Author

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants