summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-10-28 13:59:05 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-10-28 13:59:05 +0000
commit2833aa2afbd6b1529913e6ceaa565cff6e29ba95 (patch)
tree3a7a46dbd98e56846fef41811af5cb8bca6a9c91 /test/sql
parent718d9570f278be47eae2dc5dae0d218052aeffb9 (diff)
parentcaa9f0ff98d44359f5162bca8e7fe7bcaa2989a7 (diff)
downloadsqlalchemy-2833aa2afbd6b1529913e6ceaa565cff6e29ba95.tar.gz
Merge "apply basic escaping to anon_labels unconditionally" into main
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_labels.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/sql/test_labels.py b/test/sql/test_labels.py
index d385b9e8d..42d9c5f00 100644
--- a/test/sql/test_labels.py
+++ b/test/sql/test_labels.py
@@ -3,6 +3,7 @@ from sqlalchemy import Boolean
from sqlalchemy import cast
from sqlalchemy import exc as exceptions
from sqlalchemy import Integer
+from sqlalchemy import literal_column
from sqlalchemy import MetaData
from sqlalchemy import or_
from sqlalchemy import select
@@ -20,6 +21,7 @@ from sqlalchemy.sql.elements import _truncated_label
from sqlalchemy.sql.elements import ColumnElement
from sqlalchemy.sql.elements import WrapsColumnExpression
from sqlalchemy.sql.selectable import LABEL_STYLE_NONE
+from sqlalchemy.sql.visitors import prefix_anon_map
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
@@ -1038,3 +1040,35 @@ class ColExprLabelTest(fixtures.TestBase, AssertsCompiledSQL):
"SOME_COL_THING(some_table.value) "
"AS some_table_value FROM some_table",
)
+
+ @testing.combinations(
+ # the resulting strings are completely arbitrary and are not
+ # exposed in SQL with current implementations. we want to
+ # only assert that the operation doesn't fail. It's safe to
+ # change the assertion cases for this test if the label escaping
+ # format changes
+ (literal_column("'(1,2]'"), "'_1,2]'_1"),
+ (literal_column("))"), "__1"),
+ (literal_column("'%('"), "'_'_1"),
+ )
+ def test_labels_w_strformat_chars_in_isolation(self, test_case, expected):
+ """test #8724"""
+
+ pa = prefix_anon_map()
+ eq_(test_case._anon_key_label % pa, expected)
+
+ @testing.combinations(
+ (
+ select(literal_column("'(1,2]'"), literal_column("'(1,2]'")),
+ "SELECT '(1,2]', '(1,2]'",
+ ),
+ (select(literal_column("))"), literal_column("))")), "SELECT )), ))"),
+ (
+ select(literal_column("'%('"), literal_column("'%('")),
+ "SELECT '%(', '%('",
+ ),
+ )
+ def test_labels_w_strformat_chars_in_statements(self, test_case, expected):
+ """test #8724"""
+
+ self.assert_compile(test_case, expected)