From dc46737e69ddcaa227f39c95229c60cabc46dfdd Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Fri, 2 Feb 2024 23:11:40 -0800 Subject: [PATCH 1/2] vscode settings --- .vscode/settings.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2267900..9982956 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,13 +2,9 @@ "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" }, - "python.formatting.provider": "none", "python.testing.pytestArgs": ["heimdallm", "-s"], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "editor.rulers": [88], - "notebook.formatOnSave.enabled": true, - "python.linting.flake8Enabled": false, - "python.linting.mypyEnabled": true, - "python.linting.enabled": true + "notebook.formatOnSave.enabled": true } From 75f56bcc03dab6694337b36f5b8298d54ed847a3 Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Sat, 3 Feb 2024 00:24:33 -0800 Subject: [PATCH 2/2] bugfix elided tree ambiguity resolver, fixes #23 --- CHANGELOG.md | 4 ++++ .../bifrosts/sql/mysql/select/grammar.lark | 4 ++-- .../bifrosts/sql/postgres/select/grammar.lark | 4 ++-- .../bifrosts/sql/sqlite/select/grammar.lark | 4 ++-- .../sql/tests/sql/select/test_ambiguous.py | 17 +++++++++++++++++ pyproject.toml | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c46e932..314d557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/heimdallm/bifrosts/sql/mysql/select/grammar.lark b/heimdallm/bifrosts/sql/mysql/select/grammar.lark index c6b7322..2a76f21 100644 --- a/heimdallm/bifrosts/sql/mysql/select/grammar.lark +++ b/heimdallm/bifrosts/sql/mysql/select/grammar.lark @@ -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 @@ -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 diff --git a/heimdallm/bifrosts/sql/postgres/select/grammar.lark b/heimdallm/bifrosts/sql/postgres/select/grammar.lark index 4a8b97a..0aa2469 100644 --- a/heimdallm/bifrosts/sql/postgres/select/grammar.lark +++ b/heimdallm/bifrosts/sql/postgres/select/grammar.lark @@ -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 @@ -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 diff --git a/heimdallm/bifrosts/sql/sqlite/select/grammar.lark b/heimdallm/bifrosts/sql/sqlite/select/grammar.lark index d1f7710..018717b 100644 --- a/heimdallm/bifrosts/sql/sqlite/select/grammar.lark +++ b/heimdallm/bifrosts/sql/sqlite/select/grammar.lark @@ -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 @@ -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 diff --git a/heimdallm/bifrosts/sql/tests/sql/select/test_ambiguous.py b/heimdallm/bifrosts/sql/tests/sql/select/test_ambiguous.py index d600b5d..f586c76 100644 --- a/heimdallm/bifrosts/sql/tests/sql/select/test_ambiguous.py +++ b/heimdallm/bifrosts/sql/tests/sql/select/test_ambiguous.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 737454a..5d17f4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"