Skip to content

Commit

Permalink
Add tests to check that special characters '\r, \n, \t' (#94)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
surister and amotl authored Oct 7, 2024
1 parent 9d7490e commit 09f2279
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

## 2024/09/18 v0.0.7
- Improve error matching on single statement
Expand Down
15 changes: 15 additions & 0 deletions cratedb_sqlparse_js/tests/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ test('Exception message is correct', () => {

expect(stmts[0].exception.errorMessage).toBe(expectedMessage)
expect(stmts[0].exception.getOriginalQueryWithErrorMarked()).toBe(expectedMessageVerbose)
})


test('Whitetest or special characters should not avoid exception catching', () => {
// https://github.com/crate/cratedb-sqlparse/issues/67
const stmts = [
`SELECT 1\n limit `,
`SELECT 1\r limit `,
`SELECT 1\t limit `,
`SELECT 1 limit `
]
for (const stmt in stmts) {
let r = sqlparse(stmt)
expect(r[0].exception).toBeDefined();
}
})
15 changes: 15 additions & 0 deletions cratedb_sqlparse_py/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@ def test_sqlparse_collects_exceptions_3():
assert r[0].exception is None
assert r[1].exception is None
assert r[2].exception is None


def test_sqlparse_catches_exception():
from cratedb_sqlparse import sqlparse

# Special characters shouldn't avoid exception catching.
# https://github.com/crate/cratedb-sqlparse/issues/67
stmts = """
SELECT 1\n limit,
SELECT 1\r limit,
SELECT 1\t limit,
SELECT 1 limit
"""
for stmt in stmts:
assert sqlparse(stmt)[0].exception

0 comments on commit 09f2279

Please sign in to comment.