jaystack / odata-v4-parser

OData v4 parser
38 stars 41 forks source link

$orderby=foo,bar returns only duplicate foo values #12

Closed LCHarold closed 6 years ago

LCHarold commented 6 years ago

Given a querystring param of: $orderby=foo,bar

The parser is returning the correct number of items in the items array, but duplicates the first value twice. So we end up with a result of [foo, foo] instead of [foo, bar].

Here's a failing test that demonstrates this:

it('should parse multiple orderby params', () => {
    var parser = new Parser();
    var ast = parser.query("$orderby=foo,bar");
    console.log(ast.value.options[0].value.items);
    expect(ast.value.options[0].value.items[0].raw).to.equal('foo');
    expect(ast.value.options[0].value.items[1].raw).to.equal('bar');
});

and here's the output of that test:

[ Token {
    position: 9,
    next: 12,
    value: { expr: [Object], direction: 1 },
    type: 'OrderByItem',
    raw: 'foo' },
  Token {
    position: 9,
    next: 12,
    value: { expr: [Object], direction: 1 },
    type: 'OrderByItem',
    raw: 'foo' } ]
    1) should parse multiple orderby params

  1) Parser should parse multiple orderby params:

      AssertionError: expected 'foo' to equal 'bar'
      + expected - actual

      -foo
      +bar

      at Context.it (test/parser.spec.js:23:56)
lazarv commented 6 years ago

Thank you @LCHarold for finding this bug, PRs are welcome next time. Fixed version available from npm. Please update your dependencies.