Skip to content

Commit

Permalink
bugfix elided tree ambiguity resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
amoffat committed Feb 3, 2024
1 parent dc46737 commit 341f501
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.3 - 2/3/24

- Bugfix where elided tree from a boolean token triggered ambiguity resolver

## 1.0.2 - 11/10/23

- Resolving Dependabot suggestions
Expand Down
4 changes: 2 additions & 2 deletions heimdallm/bifrosts/sql/mysql/select/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ between_comparison : value (_WS NOT)? _WS BETWEEN _WS value _WS AND _WS value
// are declared, so we cannot use this there
?value : NUMBER
| string
| boolean
| BOOLEAN
| NULL
| NUMBER_PREFIX? value_expr
| NUMBER_PREFIX? fq_column
Expand All @@ -135,7 +135,7 @@ function : FUNCTION_NAME "(" \
")"
FUNCTION_NAME : /[a-zA-Z_]+/

?boolean : TRUE | FALSE
BOOLEAN : TRUE | FALSE
?string : ESCAPED_STRING

// a placeholder for a value passed in as a parameter at query execution time
Expand Down
4 changes: 2 additions & 2 deletions heimdallm/bifrosts/sql/postgres/select/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fts_comparison : value "@@" value
// are declared, so we cannot use this there
?value : PREFIX_CAST? (NUMBER
| string
| boolean
| BOOLEAN
| NULL
| NUMBER_PREFIX? value_expr
| NUMBER_PREFIX? fq_column
Expand All @@ -143,7 +143,7 @@ SUBSTRING_FN_NAME : "substring"i
EXTRACT_FN_NAME : "extract"i
CAST_FN_NAME : "cast"i

?boolean : TRUE | FALSE
BOOLEAN : TRUE | FALSE
?string : ESCAPE_PREFIX? ESCAPED_STRING

// a placeholder for a value passed in as a parameter at query execution time
Expand Down
4 changes: 2 additions & 2 deletions heimdallm/bifrosts/sql/sqlite/select/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ between_comparison : value (_WS NOT)? _WS BETWEEN _WS value _WS AND _WS value
// are declared, so we cannot use this there
?value : NUMBER
| string
| boolean
| BOOLEAN
| NULL
| NUMBER_PREFIX? value_expr
| NUMBER_PREFIX? fq_column
Expand All @@ -136,7 +136,7 @@ function : FUNCTION_NAME "(" \
")"
FUNCTION_NAME : /[a-zA-Z_]+/

?boolean : TRUE | FALSE
BOOLEAN : TRUE | FALSE
?string : ESCAPED_STRING

// a placeholder for a value passed in as a parameter at query execution time
Expand Down
17 changes: 17 additions & 0 deletions heimdallm/bifrosts/sql/tests/sql/select/test_ambiguous.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,20 @@ def test_ambiguous_arith(dialect: str, Bifrost: Type[Bifrost]):
"""

bifrost.traverse(query)


@dialects()
def test_ambiguous_bool(dialect: str, Bifrost: Type[Bifrost]):
"""A regression test to ensure that boolean tokens do not trigger the ambiguity
resolver"""
bifrost = Bifrost.validation_only(PermissiveConstraints())

query = """
SELECT
col
FROM
postings AS p
WHERE
p.is_hired = true
"""
bifrost.traverse(query)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "heimdallm"
version = "1.0.2"
version = "1.0.3"
description = "Construct trusted SQL queries from untrusted input"
homepage = "https://github.com/amoffat/HeimdaLLM"
repository = "https://github.com/amoffat/HeimdaLLM"
Expand Down

0 comments on commit 341f501

Please sign in to comment.