mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New encode/decode_path_component functions
ASGI cannot differentiate between / and %2F in a URL, so we need an
alternative scheme for encoding the names of tables that contain special
characters such as /
For background, see
https://github.com/django/asgiref/issues/51#issuecomment-450603464
Some examples:
"table/and/slashes" => "tableU+002FandU+002Fslashes"
"~table" => "U+007Etable"
"+bobcats!" => "U+002Bbobcats!"
"U+007Etable" => "UU+002B007Etable"
This commit is contained in:
parent
bfa2ae0d16
commit
9fdb47ca95
2 changed files with 37 additions and 0 deletions
|
|
@ -381,3 +381,19 @@ def test_path_with_format(path, format, extra_qs, expected):
|
|||
)
|
||||
def test_format_bytes(bytes, expected):
|
||||
assert expected == utils.format_bytes(bytes)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"name,expected",
|
||||
[
|
||||
("table", "table"),
|
||||
("table/and/slashes", "tableU+002FandU+002Fslashes"),
|
||||
("~table", "U+007Etable"),
|
||||
("+bobcats!", "U+002Bbobcats!"),
|
||||
("U+007Etable", "UU+002B007Etable"),
|
||||
],
|
||||
)
|
||||
def test_encode_decode_path_component(name, expected):
|
||||
encoded = utils.encode_path_component(name)
|
||||
assert encoded == expected
|
||||
assert name == utils.decode_path_component(encoded)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue