Soontao / odata-v4-parser

OData(V4) URI Parser
MIT License
17 stars 4 forks source link

[BUG] Strings with double quotescannot be parsed #274

Closed higleyc closed 1 year ago

higleyc commented 1 year ago

Describe the bug

If double quotes are included in string literals, parsing throws an error.

System Environment

To Reproduce

test('testStringEscapes', () => {
    let builder = ODataParam.New()
    let odfilter = ODataFilter.New()
    odfilter = odfilter.field("key").eq('val"')
    builder.filter(odfilter)
    let queryStr = builder.toString()
    console.log("queryStr:", queryStr)

    let ast = defaultParser.query(queryStr)
})

Output:

  console.log
    queryStr: $filter=key eq 'val"'

      at Object.log (__tests__/modules/structured_queries_test.ts:90:13)

 FAIL  __tests__/modules/structured_queries_test.ts
  ✕ testStringEscapes (28 ms)

  ● testStringEscapes

    Unexpected character at 11

      90 |     console.log("queryStr:", queryStr)
      91 |
    > 92 |     let ast = defaultParser.query(queryStr)
         |                             ^
      93 | })
      94 |

      at node_modules/@odata/parser/src/parser.ts:23:13
      at Parser.query (node_modules/@odata/parser/src/parser.ts:46:45)
      at Object.query (__tests__/modules/structured_queries_test.ts:92:29)

Expected behavior

Strings with double quotes should parse without error. To my understanding the encoding is correct i.e. the double quotes should be unescaped (looking at the ABNF)

Additional context

None

Soontao commented 1 year ago

cool will have a look today

Soontao commented 1 year ago

Dear @higleyc

yep this is an issue and in fact it contains more issues, some other special characters also will cause same issue, cannot be determined as primitive value string.

fix already ready and delivered with @odata/parser@0.2.14, please have a try.

BR, Theo

higleyc commented 1 year ago

Wow thank you for the quick fix @Soontao! That did it.