Skip to content

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

@bdorninger

Description

@bdorninger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions