mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Address PrefixedUrlString bug in #1075
This commit is contained in:
parent
bf18b9ba17
commit
a4ca26a265
6 changed files with 16 additions and 2 deletions
|
|
@ -822,6 +822,9 @@ class Datasette:
|
||||||
if url in seen_urls:
|
if url in seen_urls:
|
||||||
continue
|
continue
|
||||||
seen_urls.add(url)
|
seen_urls.add(url)
|
||||||
|
if url.startswith("/"):
|
||||||
|
# Take base_url into account:
|
||||||
|
url = self.urls.path(url)
|
||||||
if sri:
|
if sri:
|
||||||
output.append({"url": url, "sri": sri})
|
output.append({"url": url, "sri": sri})
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
import click
|
||||||
from collections import OrderedDict, namedtuple
|
from collections import OrderedDict, namedtuple
|
||||||
import base64
|
import base64
|
||||||
import click
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import inspect
|
import inspect
|
||||||
import itertools
|
import itertools
|
||||||
|
|
@ -1016,8 +1016,11 @@ class PrefixedUrlString(str):
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
return type(self)(super().__add__(other))
|
return type(self)(super().__add__(other))
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return super().__str__()
|
||||||
|
|
||||||
def __getattribute__(self, name):
|
def __getattribute__(self, name):
|
||||||
if name in dir(str):
|
if not name.startswith("__") and name in dir(str):
|
||||||
|
|
||||||
def method(self, *args, **kwargs):
|
def method(self, *args, **kwargs):
|
||||||
value = getattr(super(), name)(*args, **kwargs)
|
value = getattr(super(), name)(*args, **kwargs)
|
||||||
|
|
|
||||||
|
|
@ -274,6 +274,7 @@ METADATA = {
|
||||||
"source_url": "https://github.com/simonw/datasette/blob/master/tests/fixtures.py",
|
"source_url": "https://github.com/simonw/datasette/blob/master/tests/fixtures.py",
|
||||||
"about": "About Datasette",
|
"about": "About Datasette",
|
||||||
"about_url": "https://github.com/simonw/datasette",
|
"about_url": "https://github.com/simonw/datasette",
|
||||||
|
"extra_css_urls": ["/static/extra-css-urls.css"],
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"name-of-plugin": {"depth": "root"},
|
"name-of-plugin": {"depth": "root"},
|
||||||
"env-plugin": {"foo": {"$env": "FOO_ENV"}},
|
"env-plugin": {"foo": {"$env": "FOO_ENV"}},
|
||||||
|
|
|
||||||
|
|
@ -1852,6 +1852,7 @@ def test_paginate_using_link_header(app_client, qs):
|
||||||
num_pages = 0
|
num_pages = 0
|
||||||
while path:
|
while path:
|
||||||
response = app_client.get(path)
|
response = app_client.get(path)
|
||||||
|
assert response.status == 200
|
||||||
num_pages += 1
|
num_pages += 1
|
||||||
link = response.headers.get("link")
|
link = response.headers.get("link")
|
||||||
if link:
|
if link:
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ def test_serve_with_get_exit_code_for_error(tmp_path_factory):
|
||||||
"--get",
|
"--get",
|
||||||
"/this-is-404",
|
"/this-is-404",
|
||||||
],
|
],
|
||||||
|
catch_exceptions=False,
|
||||||
)
|
)
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
assert "404" in result.output
|
assert "404" in result.output
|
||||||
|
|
|
||||||
|
|
@ -1466,6 +1466,11 @@ def test_base_url_config(app_client_base_url_prefix, path):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_base_url_affects_metadata_extra_css_urls(app_client_base_url_prefix):
|
||||||
|
html = app_client_base_url_prefix.get("/").text
|
||||||
|
assert '<link rel="stylesheet" href="/prefix/static/extra-css-urls.css">' in html
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path,expected",
|
"path,expected",
|
||||||
[
|
[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue