Git Product home page Git Product logo

jmespath.test's People

Contributors

gibson042 avatar iconara avatar jamesls avatar mtdowling avatar springcomp avatar waisbrot avatar

Watchers

 avatar  avatar  avatar

Forkers

gibson042

jmespath.test's Issues

`raw-string-escape` compliance test is incorrect

Migrated from #14.

The following compliance test is incorrect:

{
"comment": "Backslash not followed by single quote is treated as any other character",
"expression": "'\\\\'",
"result": "\\\\"
}

Instead, this should be

Expression Expressed as JSON Result Comment
'\\' '\\\\' "\\" should follow raw-string-escape grammar rule

Suggested change:

         {
-          "comment": "Backslash not followed by single quote is treated as any other character",
+          "comment": "Can escape backslash",
           "expression": "'\\\\'",
-          "result": "\\\\"
+          "result": "\\"
         }

Pipe Expressions do not "correctly" handle `null` values on their left-hand-side

Sub Expression

The specification for sub-expression outlines how it should behave in pseudocode:

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

However, this is incorrect, as many compliance tests expect the result to be null when the left-hand-side evaluates to β€―null.
So, the real pseudocode shoud in fact be:

left-evaluation = search(left-expression, original-json-document)
if left-evaluation is `null` then result = `null`
else result = search(right-expression, left-evaluation)

Pipe Expression

However, it seems intuitive for pipe-expression to behave as is specified by the pseudocode above.

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

Which means that the evaluation should still happens if the left-hand-side is null.

Summary

Please, consider standardizing pipe-expression to behave like so:
search ( `null` | [@], {} ) -> [ null ]

Unicode coverage is incomplete

unicode.json does not contain any supplementary plane code points (i.e., U+10000 through U+10FFFF). This is a rather large gap for a specification in which a string is a sequence of code points, and as a result there are unsurprising bugs in e.g. the jmespath.js implementation in use at jmespath.site, which incorrectly treats each supplementary plane code point as if it were a sequence of two surrogate code points (i.e., a code point from U+D800 through U+DBFF followed by a code point from U+DC00 through U+DFFF):

expression actual result expected result
length('πŒ†') 2 1
reverse('aπŒ†b') "b\udf06\ud834a" "bπŒ†a"
sort(['πŒ†','ο₯£']) [ "πŒ†", "ο₯£" ] [ "ο₯£", "πŒ†" ]

`raw-string-char` grammar rule does not allow control characters

Migrated from #14.

The following compliance tests illustrated using control characters, such as line feed in raw-string literals.

{
"expression": "'newline\n'",
"result": "newline\n"
},
{
"expression": "'\n'",
"result": "\n"
},

Text Expression ABNF Expressed as JSON Result
newline␊ `` 'newline\n' ```` "'newline" %x0A "'" `` '\n' "\n"
␊ '\n' "'" %x0A "'" '\n' "newline\n"

However, those expressions are not valid as per the raw-string-char grammar rule:

raw-string        = "'" *raw-string-char "'" 
raw-string-char   = (%x20-26 / %x28-5B / %x5D-10FFFF) / preserved-escape / raw-string-escape 
preserved-escape  = escape (%x20-26 / %x28-5B / %x5D-10FFFF) 
raw-string-escape = escape ("'" / escape)

Please consider refactoring the compliance tests to forbid the use of C0 control characters in JMESPath expressions, as it Seems that was never the intended spirit when introduced in JEP-12.

Note: this will break non-conforming implementations.

'foo'[::-1].length(@)

In most implementations, the rhs of a sub-expression is implemented differently when the lhs is a projection.
Due to the shape of the AST, the lhs is actually evaluated on the lhs projection.

However, when slicing a string, the rhs should be treated as a regular sub-expression.

As a result, in most implementations, the following expression does not evaluate correctly:

  • 'foo'[::-1].length(@) should evaluate to 3.

In some implementations, the result is ``"oof"ornull`.

Please, consider adding a compliance test.

Pipe evaluation with multi-select-[list / hash]

Seems there are some inconsistent implementations, even in JMESPath Community.

  • search( `null` | [@] , null ) -> [ null ] βœ”οΈ
  • search( `null` | { foo: @ } ) -> null ❌

We think this MUST return {"foo": null} instead for consistency.

raw string literal testing disagrees with documentation

jmespath.site Grammar defines the grammar for raw string literals like

raw-string        = "'" *raw-string-char "'" 
raw-string-char   = (%x20-26 / %x28-5B / %x5D-10FFFF) / preserved-escape / raw-string-escape 
preserved-escape  = escape (%x20-26 / %x28-5B / %x5D-10FFFF) 
raw-string-escape = escape ("'" / escape)

and Raw String Literals includes a search('\\', "") -> "\\" example implying that \\ is an escape sequence representing a single U+005C REVERSE SOLIDUS just like \' is an escape sequence representing a single U+0027 APOSTROPHE.

However, tests/literal.json in this repository includes test cases contradicting the above, such as { "expression": "'\n'", "result": "\n" } (a raw string literal including a U+000A LINE FEED, which is not covered by raw-string-char) and { "comment": "Backslash not followed by single quote is treated as any other character", "expression": "'\\\\'", "result": "\\\\" } (added in 2016 by c0f7923).

Both disagreements ultimately affect whether or not raw string literals are capable of representing all possible sequences of code points (respectively those including C0 control characters and those including U+005C REVERSE SOLIDUS), and the latter is especially oddβ€”I've never heard of any other escaping approach in which the escape prefix itself is unrepresentable.

Issue with filters and projections

Most implementations seems to have the following issue:

Given the following JSON:

[
  {
    "stack": "",
    "branch": [
      "one/",
      "two/"
    ]
  },
  { "branch": ["three/", "four/"]}
]

The following expression yields an incorrect result:

  • [?stack==''].branch[?starts_with(@, 'one')] -> invalid-type

In contrast, the following similar expression returns the expected result:

  • [].branch[?starts_with(@, 'one')] -> [ [ "one/" ], [] ]

Please consider adding a compliance test and fixing the libraries.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.