From 10a6e82f9a22f6f9fadc865b65f06697baa1c30d Mon Sep 17 00:00:00 2001 From: Guillermo Date: Mon, 25 May 2026 17:55:15 +0200 Subject: [PATCH] fix: quote convert dry-run identifiers --- sqlite_utils/cli.py | 10 +++++----- tests/test_cli_convert.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index 5844dfc0..5a0ff602 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -3088,12 +3088,12 @@ def preview(v): db.conn.create_function("preview_transform", 1, preview) sql = """ select - [{column}] as value, - preview_transform([{column}]) as preview - from [{table}]{where} limit 10 + {column} as value, + preview_transform({column}) as preview + from {table}{where} limit 10 """.format( - column=columns[0], - table=table, + column=quote_identifier(columns[0]), + table=quote_identifier(table), where=" where {}".format(where) if where is not None else "", ) for row in db.conn.execute(sql, where_args).fetchall(): diff --git a/tests/test_cli_convert.py b/tests/test_cli_convert.py index 443e72c6..e19feade 100644 --- a/tests/test_cli_convert.py +++ b/tests/test_cli_convert.py @@ -179,6 +179,25 @@ def test_convert_dryrun(test_db_and_path): assert result.output.strip().split("\n")[-1] == "Would affect 1 row" +def test_convert_dryrun_identifier_with_closing_bracket(tmpdir): + db_path = str(pathlib.Path(tmpdir) / "data.db") + db = sqlite_utils.Database(db_path) + db["example]table"].insert({"value]x": "alpha"}) + result = CliRunner().invoke( + cli.cli, + [ + "convert", + db_path, + "example]table", + "value]x", + "value.upper()", + "--dry-run", + ], + ) + assert result.exit_code == 0, result.output + assert result.output.strip() == "alpha\n --- becomes:\nALPHA\n\nWould affect 1 row" + + def test_convert_multi_dryrun(test_db_and_path): db_path = test_db_and_path[1] result = CliRunner().invoke(