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

Comparing attribute values, which contain a semicolon, does not work #187

Open
bdorninger opened this issue May 4, 2023 · 3 comments
Open

Comments

@bdorninger
Copy link

Describe the bug

Comparing attribute values, which contain a semicolon does not work

Code sample or steps to reproduce

// Note the xyz; contains a semicolon
export const foodata = {
  obj: [{ foo: 'abc' }, { foo: 'xyz;' }, { foo: 'efg' }],
};

// CASE 1 
// WORKS!! Produces 1 result
let result = JSONPath({
  path: `$..*[?(@.foo==="abc")]`,
  json: foodata,
});

console.assert(result.length > 0, 'Nothing found for simple comparison ');

// CASE 2:
// semicolon directly specified in the key string 
// BUT DOES NOT WORK!!! No results
result = JSONPath({
  path: `$..*[?(@.foo==="xyz;")]`,
  json: foodata,
});

console.assert(result.length > 0, 'Nothing found with direct use of ";" ');

// CASE 3
// WORKAROUND : Need to specify the semicolon with an escape expression
// WORKS!!! Produces 1 result
result = JSONPath({
  path: `$..*[?(@.foo==="xyz\\u003b")]`,
  json: foodata,
});

console.assert(
  result.length > 0,
  'Nothing found with escaped version of semicolon'
);

Console error or logs

Assertion failed: Nothing found with direct use of ";"

Expected behavior

Case 2 should work as Case1, i.e. a client should not need to escape the semicolon in the comparison operand

Expected result

For Case 2 the same as for Case 3

{ foo: 'xyz;' }

Environment (IMPORTANT)

  • JSONPath-Plus version: 7.2.0

Desktop**

  • OS: Win11
  • Chrome 112

Additional context

@rafalkrupinski
Copy link

I have a closely related problem.

I'm trying to select this path:

JSONPath({path:"$.paths./documents/.post.responses.201.content['application/json; version=2.4.42'].schema", json})

I also checked toPathArray which shows the mime split into two components: 'application/json', ' version=2.4.42'.
I also tried escaping the semicolon, but without any result.

@rafalkrupinski
Copy link

the code is doing funny things here

const exprList = normalized.split(';').map(function (exp) {

@rafalkrupinski
Copy link

As a workaround a simple patch in JSONPath._trace() could add support for escaped unicode characters ("\u003b"->";") that would happen after the semicolon is used as a token separator in the normalization block of JSONPath.toPathArray()

  const loc_ = expr[0], x = expr.slice(1);

  const loc = (typeof loc_ === 'string')?loc_.replace(/\\u([\dA-Fa-f]{4})/g, (_, group) => {
    return String.fromCharCode(parseInt(group, 16));
  })  : loc_;

A support for escaped unicode characters is also nice to have on its own.

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