Skip to content

Whitespace character handling #58

Open

Description

@SamMousa

There is a discrepancy with how the JS library parses whitespace vs the PHP library.

 $p  = new \JmesPath\Parser();
var_dump($p->parse("[]\r[]"));
array(3) {
  ["type"]=>
  string(10) "projection"
  ["from"]=>
  string(5) "array"
  ["children"]=>
  array(2) {
    [0]=>
    array(2) {
      ["type"]=>
      string(7) "flatten"
      ["children"]=>
      array(1) {
        [0]=>
        array(3) {
          ["type"]=>
          string(10) "projection"
          ["from"]=>
          string(5) "array"
          ["children"]=>
          array(2) {
            [0]=>
            array(2) {
              ["type"]=>
              string(7) "flatten"
              ["children"]=>
              array(1) {
                [0]=>
                array(1) {
                  ["type"]=>
                  string(7) "current"
                }
              }
            }
            [1]=>
            array(1) {
              ["type"]=>
              string(7) "current"
            }
          }
        }
      }
    }
    [1]=>
    array(1) {
      ["type"]=>
      string(7) "current"
    }
  }
}
jmespath.compile("[]\r[]");
jmespath.js:309 Uncaught LexerError: Unknown character:
    at Lexer.tokenize (https://run.plnkr.co/preview/ck3fuluzv0006315wgzsg94tg/jmespath.js:307:31)
    at Parser._loadTokens (https://run.plnkr.co/preview/ck3fuluzv0006315wgzsg94tg/jmespath.js:523:30)
    at Parser.parse (https://run.plnkr.co/preview/ck3fuluzv0006315wgzsg94tg/jmespath.js:508:16)
    at Object.compile (https://run.plnkr.co/preview/ck3fuluzv0006315wgzsg94tg/jmespath.js:1647:22)
    at <anonymous>:1:10

It seems to me 1 of the implementations is wrong, not sure which.

Activity

  1. SamMousa commented on Nov 26, 2019

    @SamMousa
    Author

    Javascript uses this: https://github.com/jmespath/jmespath.js/blob/master/jmespath.js#L212

      var skipChars = {
          " ": true,
          "\t": true,
          "\n": true
      };

    PHP uses this: https://github.com/jmespath/jmespath.php/blob/master/src/Lexer.php#L73

            ' '  => self::STATE_WHITESPACE,
            "\t" => self::STATE_WHITESPACE,
            "\n" => self::STATE_WHITESPACE,
            "\r" => self::STATE_WHITESPACE,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions