mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-21 16:04:10 +02:00
cli: output JSON without escaping non-ASCII characters
Closes #625. json.dumps defaults to ensure_ascii=True, so output_rows emitted '\u65e5\u672c\u8a9e' instead of '日本語' for Japanese. The CSV path already shows the characters verbatim - the JSON path should too. Pass ensure_ascii=False so the bytes match what the CSV output (and the database itself) holds. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This commit is contained in:
parent
8f0c06e188
commit
4bfb53aae3
2 changed files with 12 additions and 1 deletions
|
|
@ -738,6 +738,17 @@ def test_query_json(db_path, sql, args, expected):
|
|||
assert expected == result.output.strip()
|
||||
|
||||
|
||||
def test_query_json_unicode(db_path):
|
||||
# Regression for #625: JSON output should keep non-ASCII characters
|
||||
# as themselves, not as \u-escapes.
|
||||
db = Database(db_path)
|
||||
with db.conn:
|
||||
db["t"].insert({"id": 1, "text": "Japanese 日本語"})
|
||||
result = CliRunner().invoke(cli.cli, [db_path, "select id, text from t"])
|
||||
assert "日本語" in result.output
|
||||
assert "\\u65e5" not in result.output
|
||||
|
||||
|
||||
def test_query_json_empty(db_path):
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue