Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to check that special characters '\r, \n, \t' #94

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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