Skip to content

Commit 09f2279

Browse files
suristeramotl
andauthored
Add tests to check that special characters '\r, \n, \t' (#94)
* Add tests to check that special characters '\r, \n, \t' don't block exception collecting Co-authored-by: Andreas Motl <[email protected]> --------- Co-authored-by: Andreas Motl <[email protected]>
1 parent 9d7490e commit 09f2279

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
- Export `Statement` in both Python and Javascript target
5+
- Fixed query parsing when expression includes special characters like `\n`, `\r`, or `\t`
56

67
## 2024/09/18 v0.0.7
78
- Improve error matching on single statement

cratedb_sqlparse_js/tests/exceptions.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,19 @@ test('Exception message is correct', () => {
7070

7171
expect(stmts[0].exception.errorMessage).toBe(expectedMessage)
7272
expect(stmts[0].exception.getOriginalQueryWithErrorMarked()).toBe(expectedMessageVerbose)
73+
})
74+
75+
76+
test('Whitetest or special characters should not avoid exception catching', () => {
77+
// https://github.com/crate/cratedb-sqlparse/issues/67
78+
const stmts = [
79+
`SELECT 1\n limit `,
80+
`SELECT 1\r limit `,
81+
`SELECT 1\t limit `,
82+
`SELECT 1 limit `
83+
]
84+
for (const stmt in stmts) {
85+
let r = sqlparse(stmt)
86+
expect(r[0].exception).toBeDefined();
87+
}
7388
})

cratedb_sqlparse_py/tests/test_exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,18 @@ def test_sqlparse_collects_exceptions_3():
8383
assert r[0].exception is None
8484
assert r[1].exception is None
8585
assert r[2].exception is None
86+
87+
88+
def test_sqlparse_catches_exception():
89+
from cratedb_sqlparse import sqlparse
90+
91+
# Special characters shouldn't avoid exception catching.
92+
# https://github.com/crate/cratedb-sqlparse/issues/67
93+
stmts = """
94+
SELECT 1\n limit,
95+
SELECT 1\r limit,
96+
SELECT 1\t limit,
97+
SELECT 1 limit
98+
"""
99+
for stmt in stmts:
100+
assert sqlparse(stmt)[0].exception

0 commit comments

Comments
 (0)