diff --git a/datasette/views/base.py b/datasette/views/base.py index 2c14be57..4d783a07 100644 --- a/datasette/views/base.py +++ b/datasette/views/base.py @@ -203,6 +203,8 @@ class DataView(BaseView): hash = None else: name = db_name + if "%" in name: + name = urllib.parse.unquote_plus(name) # Verify the hash try: db = self.ds.databases[name] diff --git a/tests/fixtures.py b/tests/fixtures.py index dac28dc0..4ba816e6 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -215,6 +215,11 @@ def app_client_with_dot(): yield from make_app_client(filename="fixtures.dot.db") +@pytest.fixture(scope="session") +def app_client_with_space(): + yield from make_app_client(filename="fixtures with space.db") + + @pytest.fixture(scope="session") def app_client_with_cors(): yield from make_app_client(cors=True) diff --git a/tests/test_api.py b/tests/test_api.py index cc00b780..163e2ec7 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -9,6 +9,7 @@ from .fixtures import ( # noqa app_client_two_attached_databases_one_immutable, app_client_with_cors, app_client_with_dot, + app_client_with_space, generate_compound_rows, generate_sortable_rows, make_app_client, @@ -544,6 +545,11 @@ def test_database_page_for_database_with_dot_in_name(app_client_with_dot): assert 200 == response.status +def test_database_page_for_database_with_space_in_name(app_client_with_space): + response = app_client_with_space.get("/fixtures%20with%20space.json") + assert 200 == response.status + + def test_custom_sql(app_client): response = app_client.get( "/fixtures.json?sql=select+content+from+simple_primary_key&_shape=objects"