From 10067c3ceb7e232b2dc5b9e60b3216100f5e1594 Mon Sep 17 00:00:00 2001 From: Petros Angelatos Date: Thu, 6 Dec 2018 00:58:08 -0800 Subject: [PATCH] recurse to correct rule for nested expand paths Fixes inputs like /resource?$expand=foo/bar($filter=foo) Change-type: patch Signed-off-by: Petros Angelatos --- odata-parser.pegjs | 2 +- test/expand.coffee | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/odata-parser.pegjs b/odata-parser.pegjs index 37f4f3f..a9045fe 100644 --- a/odata-parser.pegjs +++ b/odata-parser.pegjs @@ -439,7 +439,7 @@ ExpandPropertyPath = )? next:( '/' - @PropertyPath + @ExpandPropertyPath )? { return { name: resource, property: next, count: count, options: optionsObj} } diff --git a/test/expand.coffee b/test/expand.coffee index 600e8a4..1fb80a4 100644 --- a/test/expand.coffee +++ b/test/expand.coffee @@ -38,6 +38,28 @@ module.exports = testExpands = (test, nested = 1) -> assert.equal(result.options.$expand.properties[0].name, 'Products') expectation(result.options?.$expand?.properties?[0]) + test "$expand=Products/Suppliers(#{input})", optArgs..., (result) -> + it 'has an options property', -> + assert.notEqual(result.options, null) + it 'has an $expand value', -> + assert.notEqual(result.options.$expand, null) + it 'has a resource of Products', -> + assert.equal(result.options.$expand.properties[0].name, 'Products') + it 'has a child path of Suppliers', -> + assert.equal(result.options.$expand.properties[0].property.name, 'Suppliers') + expectation(result.options?.$expand?.properties?[0].property) + + test "$expand=Products,Suppliers(#{input})", optArgs..., (result) -> + it 'has an options property', -> + assert.notEqual(result.options, null) + it 'has an $expand value', -> + assert.notEqual(result.options.$expand, null) + it 'has a resource of Products', -> + assert.equal(result.options.$expand.properties[0].name, 'Products') + it 'has a resource of Suppliers', -> + assert.equal(result.options.$expand.properties[1].name, 'Suppliers') + expectation(result.options?.$expand?.properties?[1]) + testExpandOptionCount = (test, input, optArgs..., expectation) -> test "$expand=Products/$count(#{input})", optArgs..., (result) -> it 'has an options property', ->