Handle spaces in DB names (#590)

Closes #503 - thanks, @rixx
col-nocol
Tobias Kunze 2019-11-05 00:16:30 +01:00 zatwierdzone przez Simon Willison
rodzic 52fa79c607
commit 931bfc6661
4 zmienionych plików z 26 dodań i 8 usunięć

Wyświetl plik

@ -203,12 +203,13 @@ class DataView(BaseView):
hash = hash_bit
else:
name = db_name
# Verify the hash
name = urllib.parse.unquote_plus(name)
try:
db = self.ds.databases[name]
except KeyError:
raise NotFound("Database not found: {}".format(name))
# Verify the hash
expected = "000"
if db.hash is not None:
expected = db.hash[:HASH_LENGTH]

Wyświetl plik

@ -174,7 +174,7 @@ def app_client_no_files():
@pytest.fixture(scope="session")
def app_client_two_attached_databases():
yield from make_app_client(
extra_databases={"extra_database.db": EXTRA_DATABASE_SQL}
extra_databases={"extra database.db": EXTRA_DATABASE_SQL}
)
@ -188,7 +188,7 @@ def app_client_conflicting_database_names():
@pytest.fixture(scope="session")
def app_client_two_attached_databases_one_immutable():
yield from make_app_client(
is_immutable=True, extra_databases={"extra_database.db": EXTRA_DATABASE_SQL}
is_immutable=True, extra_databases={"extra database.db": EXTRA_DATABASE_SQL}
)

Wyświetl plik

@ -6,6 +6,7 @@ from .fixtures import ( # noqa
app_client_shorter_time_limit,
app_client_larger_cache_size,
app_client_returned_rows_matches_page_size,
app_client_two_attached_databases,
app_client_two_attached_databases_one_immutable,
app_client_conflicting_database_names,
app_client_with_cors,
@ -1188,7 +1189,7 @@ def test_databases_json(app_client_two_attached_databases_one_immutable):
databases = response.json
assert 2 == len(databases)
extra_database, fixtures_database = databases
assert "extra_database" == extra_database["name"]
assert "extra database" == extra_database["name"]
assert None == extra_database["hash"]
assert True == extra_database["is_mutable"]
assert False == extra_database["is_memory"]
@ -1679,6 +1680,22 @@ def test_cors(app_client_with_cors, path, status_code):
assert "*" == response.headers["Access-Control-Allow-Origin"]
@pytest.mark.parametrize(
"path",
(
"/",
".json",
"/searchable",
"/searchable.json",
"/searchable_view",
"/searchable_view.json",
),
)
def test_database_with_space_in_name(app_client_two_attached_databases, path):
response = app_client_two_attached_databases.get("/extra database" + path)
assert response.status == 200
def test_common_prefix_database_names(app_client_conflicting_database_names):
# https://github.com/simonw/datasette/issues/597
assert ["fixtures", "foo", "foo-bar"] == [

Wyświetl plik

@ -27,11 +27,11 @@ def test_homepage(app_client_two_attached_databases):
# Should be two attached databases
assert [
{"href": "/fixtures", "text": "fixtures"},
{"href": "/extra_database", "text": "extra_database"},
{"href": "/extra database", "text": "extra database"},
] == [{"href": a["href"], "text": a.text.strip()} for a in soup.select("h2 a")]
# The first attached database should show count text and attached tables
h2 = soup.select("h2")[1]
assert "extra_database" == h2.text.strip()
assert "extra database" == h2.text.strip()
counts_p, links_p = h2.find_all_next("p")[:2]
assert (
"2 rows in 1 table, 5 rows in 4 hidden tables, 1 view" == counts_p.text.strip()
@ -41,8 +41,8 @@ def test_homepage(app_client_two_attached_databases):
{"href": a["href"], "text": a.text.strip()} for a in links_p.findAll("a")
]
assert [
{"href": "/extra_database/searchable", "text": "searchable"},
{"href": "/extra_database/searchable_view", "text": "searchable_view"},
{"href": "/extra database/searchable", "text": "searchable"},
{"href": "/extra database/searchable_view", "text": "searchable_view"},
] == table_links