Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export namespace Query {
if (!eq) return;
index = eq;

while (value[index] !== 0x26 && index < value.length) index++;
// read to next ampersand, semicolon, or close paren
while (value[index] !== 0x26 && value[index] !== 0x3B && value[index] !== 0x29 && index < value.length) index++;
if (index === eq) return;

return Lexer.tokenize(value, start, index, { key: key.raw, value: Utils.stringify(value, eq, index) }, Lexer.TokenType.CustomQueryOption);
Expand Down Expand Up @@ -250,6 +251,7 @@ export namespace Query {

export function expandRefOption(value: Utils.SourceArray, index: number): Lexer.Token {
return Query.expandCountOption(value, index) ||
Query.customQueryOption(value, index) ||
Query.orderby(value, index) ||
Query.skip(value, index) ||
Query.top(value, index) ||
Expand Down
20 changes: 20 additions & 0 deletions test/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ describe("Parser", () => {
expect(ast.value.options[0].value.items[1].raw).to.equal("bar");
});

it("should parse solo custom query option in $expand clause", () => {
var parser = new Parser();
var ast = parser.query("$expand=Items(skipToken=100)");
expect(ast.value.options[0].value.items[0].value.options[0].value.value).to.equal("100");
});

it("should parse custom query options in $expand clause", () => {
var parser = new Parser();
var ast = parser.query("$expand=Items($top=1;skipToken=100)");
expect(ast.value.options[0].value.items[0].value.options[0].value.raw).to.equal("1");
expect(ast.value.options[0].value.items[0].value.options[1].value.value).to.equal("100");
});

it("should parse custom query options in $expand clause when custom query option is first", () => {
var parser = new Parser();
var ast = parser.query("$expand=Items(skipToken=100;$top=1)");
expect(ast.value.options[0].value.items[0].value.options[0].value.value).to.equal("100");
expect(ast.value.options[0].value.items[0].value.options[1].value.raw).to.equal("1");
});

it("should parse custom query options", () => {
var parser = new Parser();
var ast = parser.query("foo=123&bar=foobar");
Expand Down