From fd3224aa056e049b364faf8f1c53614b6b07c4b8 Mon Sep 17 00:00:00 2001 From: Daniel Shafer Date: Sun, 11 Oct 2026 14:33:57 +0000 Subject: [PATCH] Quote filenames in the datasette inspect line of generated Dockerfiles, closes #1233 make_dockerfile() already shell-quoted the -i arguments in the CMD line, but joined the files for the RUN datasette inspect line with plain spaces, so a database called 'extra database.db' was split into two arguments and the Docker build failed with "Path 'extra' does not exist". Co-Authored-By: Claude Opus 5.5 --- datasette/utils/__init__.py | 2 +- tests/test_package.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/datasette/utils/__init__.py b/datasette/utils/__init__.py index 669d04c7..55c80139 100644 --- a/datasette/utils/__init__.py +++ b/datasette/utils/__init__.py @@ -649,7 +649,7 @@ CMD {cmd}""".format( [f"ENV {key} '{value}'" for key, value in environment_variables.items()] ), install_from=" ".join(install), - files=" ".join(files), + files=" ".join(shlex.quote(f) for f in files), port=port, cmd=cmd, ).strip() diff --git a/tests/test_package.py b/tests/test_package.py index 43b20589..db5e3fb0 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -59,3 +59,25 @@ def test_package_with_port(mock_call, mock_which, tmp_path_factory): ) assert 0 == result.exit_code assert EXPECTED_DOCKERFILE.format(port=8080) == capture.captured + + +@mock.patch("shutil.which") +@mock.patch("datasette.cli.call") +def test_package_filename_with_space(mock_call, mock_which, tmp_path_factory): + # https://github.com/simonw/datasette/issues/1233 + mock_which.return_value = True + capture = CaptureDockerfile() + mock_call.side_effect = capture + runner = CliRunner() + os.chdir(tmp_path_factory.mktemp("runner")) + with open("extra database.db", "w") as fp: + fp.write("data") + result = runner.invoke( + cli.cli, ["package", "extra database.db", "--secret", "sekrit"] + ) + assert 0 == result.exit_code + assert ( + "RUN datasette inspect 'extra database.db' --inspect-file inspect-data.json" + in capture.captured + ) + assert "-i 'extra database.db'" in capture.captured