@@ -174,9 +174,7 @@ def test_flatten_nested_array_column_value_count(self):
174174 if cols and vals :
175175 c_count = len ([c for c in cols .group (1 ).split ("," ) if c .strip ()])
176176 v_count = len ([v for v in vals .group (1 ).split ("," ) if v .strip ()])
177- assert c_count == v_count , (
178- f"Column count ({ c_count } ) != value count ({ v_count } )"
179- )
177+ assert c_count == v_count , f"Column count ({ c_count } ) != value count ({ v_count } )"
180178
181179 def test_flatten_mixed_nested_array_and_object_count (self ):
182180 """
@@ -201,9 +199,7 @@ def test_flatten_mixed_nested_array_and_object_count(self):
201199 if cols and vals :
202200 c_count = len ([c for c in cols .group (1 ).split ("," ) if c .strip ()])
203201 v_count = len ([v for v in vals .group (1 ).split ("," ) if v .strip ()])
204- assert c_count == v_count , (
205- f"Column count ({ c_count } ) != value count ({ v_count } )"
206- )
202+ assert c_count == v_count , f"Column count ({ c_count } ) != value count ({ v_count } )"
207203
208204
209205class TestFlattenDetail :
@@ -401,6 +397,28 @@ def test_string_with_quotes(self, converter_postgres):
401397 result = converter_postgres .convert (data , table_name = "profiles" )
402398 assert "It''s a test" in result # SQL-escaped single quote
403399
400+ def test_key_with_embedded_double_quote_postgres (self , converter_postgres ):
401+ # A JSON key containing " must be escaped in the generated identifier
402+ # to prevent SQL injection through untrusted object keys.
403+ data = json .dumps ({'col"evil' : 1 })
404+ result = converter_postgres .convert (data , table_name = "profiles" )
405+ assert '"col""evil"' in result
406+ # Ensure the dangerous unescaped form is NOT present
407+ assert '"col"evil"' not in result
408+
409+ def test_key_with_embedded_double_quote_sqlite (self , converter_sqlite ):
410+ data = json .dumps ({'col"evil' : 1 })
411+ result = converter_sqlite .convert (data , table_name = "profiles" )
412+ assert '"col""evil"' in result
413+ assert '"col"evil"' not in result
414+
415+ def test_key_with_embedded_backtick_mysql (self , converter_mysql ):
416+ # A JSON key containing a backtick must be escaped in MySQL identifiers.
417+ data = json .dumps ({"col`evil" : 1 })
418+ result = converter_mysql .convert (data , table_name = "profiles" )
419+ assert "`col``evil`" in result
420+ assert "`col`evil`" not in result
421+
404422 def test_float_values (self , converter_postgres ):
405423 data = json .dumps ({"price" : 19.99 })
406424 result = converter_postgres .convert (data , table_name = "products" )
@@ -515,6 +533,5 @@ def test_version_in_init_matches_pyproject(self):
515533 with open (pyproject , "rb" ) as f :
516534 data = tomllib .load (f )
517535 assert data ["project" ]["version" ] == __version__ , (
518- f"pyproject.toml version ({ data ['project' ]['version' ]} ) != "
519- f"__init__.__version__ ({ __version__ } )"
536+ f"pyproject.toml version ({ data ['project' ]['version' ]} ) != __init__.__version__ ({ __version__ } )"
520537 )
0 commit comments