From 3ba6b9398fae3f158d0025ac5ee2a83af4571ce7 Mon Sep 17 00:00:00 2001 From: lostfields Date: Fri, 8 Mar 2024 08:02:07 +0100 Subject: [PATCH] fix: double slash #deploy_branch --- src/linq/peg/grammar/odata.pegjs | 4 ++-- src/linq/peg/parser/odata-parser.js | 6 +++--- src/test/translator/odata.ts | 9 ++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/linq/peg/grammar/odata.pegjs b/src/linq/peg/grammar/odata.pegjs index 3dd6463..d8f70f2 100644 --- a/src/linq/peg/grammar/odata.pegjs +++ b/src/linq/peg/grammar/odata.pegjs @@ -343,8 +343,8 @@ HexDigit = [a-f] / [A-F] / [0-9] StringLiteral - = "'" chars:(Escape / ![\\'\n\r] . )* "'" - { return { type: 'Literal', value: chars.map(l => l[0] || l[1]).join('').replace(/\\\\/g, '\\') } } + = "'" chars:(Escape / !['\n\r] . )* "'" + { return { type: 'Literal', value: chars.map(l => l[0] || l[1]).join('') } } ArrayLiteral = LPAR __ elements:(first:Expression rest:(COMMA __ Expression)* { return buildList(first, rest, 2)})? (COMMA __)? __ RPAR __ diff --git a/src/linq/peg/parser/odata-parser.js b/src/linq/peg/parser/odata-parser.js index 50f98b6..384fab6 100644 --- a/src/linq/peg/parser/odata-parser.js +++ b/src/linq/peg/parser/odata-parser.js @@ -231,7 +231,7 @@ function peg$parse(input, options) { var peg$r11 = /^[+\-]/; var peg$r12 = /^[pP]/; var peg$r13 = /^[0-9A-Fa-f]/; - var peg$r14 = /^[\\'\n\r]/; + var peg$r14 = /^['\n\r]/; var peg$r15 = /^[btnfr"'\\]/; var peg$r16 = /^[0-3]/; @@ -266,7 +266,7 @@ function peg$parse(input, options) { var peg$e28 = peg$classExpectation(["+", "-"], false, false); var peg$e29 = peg$classExpectation(["p", "P"], false, false); var peg$e30 = peg$classExpectation([["0", "9"], ["A", "F"], ["a", "f"]], false, false); - var peg$e31 = peg$classExpectation(["\\", "'", "\n", "\r"], false, false); + var peg$e31 = peg$classExpectation(["'", "\n", "\r"], false, false); var peg$e32 = peg$anyExpectation(); var peg$e33 = peg$literalExpectation("''", false); var peg$e34 = peg$literalExpectation("\\", false); @@ -438,7 +438,7 @@ function peg$parse(input, options) { var peg$f26 = function(value) { return { type: 'DateLiteral', value: flattenArray(value).join('') }; }; var peg$f27 = function(first, value, last) { return { type: 'DateLiteral', value: flattenArray(value).join('') }; }; var peg$f28 = function() { return { type: 'NumberLiteral', value: text() }; }; - var peg$f29 = function(chars) { return { type: 'Literal', value: chars.map(l => l[0] || l[1]).join('').replace(/\\\\/g, '\\') } }; + var peg$f29 = function(chars) { return { type: 'Literal', value: chars.map(l => l[0] || l[1]).join('') } }; var peg$f30 = function(first, rest) { return buildList(first, rest, 2)}; var peg$f31 = function(elements) { return { type: 'ArrayLiteral', elements: elements } }; var peg$currPos = options.peg$currPos | 0; diff --git a/src/test/translator/odata.ts b/src/test/translator/odata.ts index 6f0388c..614bf83 100644 --- a/src/test/translator/odata.ts +++ b/src/test/translator/odata.ts @@ -49,7 +49,14 @@ describe('When using Translator', () => { let odata = translator.visit(expr) chai.expect(odata).to.equal(`contains(customer/name, 'ka\\e')`) - }) + }) + + it('should handle escape of character \\ twice', () => { + let expr = visitor.parseOData(`contains(customer/name, 'ka\\\\e')`) + let odata = translator.visit(expr) + + chai.expect(odata).to.equal(`contains(customer/name, 'ka\\\\e')`) + }) it('should handle unicode if that is a thing', () => { let expr = visitor.parseOData(`contains(customer/name, 'ka\\u1128')`)