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

No exception thrown when using an empty json path on calling json_query #305

Closed
Flow86 opened this issue Jan 26, 2021 · 3 comments
Closed

Comments

@Flow86
Copy link
Contributor

Flow86 commented Jan 26, 2021

After upgrading from v0.144.0 I encountered an issue when using an empty json path:
With the old version I got an exception thrown "The provided JSONPath is incorrect.".
With the new version, an empty result is returned.

I thought that an empty json path is invalid?

What is the expected behavior?
Exception thrown when using an empty json path (= invalid) on calling json_query

What is the actual behavior?
An empty result is returned.

Enumerate the steps to reproduce the bug
query jsoncons::jsonpath::json_query with an empty path

Include a small, self-contained example if possible

auto json = jsoncons::json::parse(R"({ "a": 1 })");
auto path = "";
auto result = jsoncons::jsonpath::json_query(json, path);
// expected: exception jsoncons::jsonpath::jsonpath_error thrown
// actual: result.empty() == true

What compiler, architecture, and operating system?

  • Compiler: MSVC / clang
  • Architecture: x64
  • Operating system: Windows, Linux (Debian)

What jsoncons library version?

  • Latest release v0.160.0
@Flow86 Flow86 added the Bug label Jan 26, 2021
@Flow86
Copy link
Contributor Author

Flow86 commented Jan 26, 2021

Ah, It seems this behavior was changed in #270 by purpose

@Flow86 Flow86 closed this as completed Jan 26, 2021
@danielaparker
Copy link
Owner

danielaparker commented Jan 26, 2021

Reopening. It was changed, but I'm no longer sure that was right. We're currently working on a major rewrite of the jsonpath extension, and may reconsider that. Generally, we want syntax errors in the path expression to be reported, and execution errors when applying the path to a particular JSON instance to result in an empty array.

Comparing with other implementations:

Empty

@danielaparker
Copy link
Owner

As of the next release, 0.161.0, an empty JSONPath string will be regarded as a syntax error and an error will be raised, see #306.

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

No branches or pull requests

2 participants