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

Whitespace character handling #58

Open
SamMousa opened this issue Nov 26, 2019 · 1 comment
Open

Whitespace character handling #58

SamMousa opened this issue Nov 26, 2019 · 1 comment

Comments

@SamMousa
Copy link

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.

@SamMousa
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant