orientechnologies / orientechnologies/orientdb
Escaped entities and newlines inside quotes cause an exception in the SQL parser
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 5k
- Forks
- 868
- Avg merge
- 15h 6m
- Merged PRs (30d)
- 18
Description
OrientDB Version: 3.1.8 (docker)
In some cases, quoted strings containing escaped entities and/or newlines ("foo \n bar") fail to be parsed by the SQL parser. This happens both from Studio and through OrientJS batch.
Expected behavior
Newlines and escaped entities inside quoted strings do not crash the parser.
Actual behavior
Having any escaped character or a newline inside a quoted string will cause an exception in the SQL parser:
com.orientechnologies.orient.core.sql.parser.TokenMgrError: Lexical error at line 148, column 47. Encountered: "\n" (10), after : "\""
Steps to reproduce
This seems to happen wherever there can be a quoted string. Some examples:
eval() doesn't like multiline expressions:
LET $test = eval("
TRUE
OR FALSE
");
RegExp is prone to breakage due to the frequent need to escape some characters:
CREATE FUNCTION newlineTest
"var foo = \"[test]\";
return /\\[[a-z]+\\]/.test(foo);"
IDEMPOTENT TRUE
LANGUAGE JAVASCRIPT;
Related issues
Newline in batch CREATE FUNCTION causes lexical error in OrientDB – orientjs#444
query runs fine in console, in web gui, but not over REST-API – orientdb#8206 – the same happens with single quotes.
OrientDB 2.1 Migration - newlines in quoted SQL string – oriendb#4837
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the SQL parser entry point and reproduce the quoted-string cases from the issue, including the multiline eval() expression and CREATE FUNCTION example. Trace the lexical error for escaped characters, newlines, and single-quoted strings, then add or update parser coverage so these inputs complete without exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100