Skip to content

Commit 063ec95

Browse files
committed
fix? url_encode aggressively encoding brackets
1 parent a188497 commit 063ec95

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

library/utils/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ def safe_quote(url):
838838

839839
def selective_quote(component, restricted_chars):
840840
try:
841-
quoted = quote(component, errors="strict")
841+
quoted = quote(component, safe="/:[]@!$&'()*+,;=", errors="strict")
842842
except UnicodeDecodeError:
843843
return component
844844
return "".join(quote(char, safe="%") if char in restricted_chars else char for char in quoted)

tests/playback/test_links_open.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ def test_links_open(mock_souffle):
1818
{"path": "https://site1", "hostname": "site1", "category": "p1"},
1919
{"path": "https://site2", "hostname": "site2", "category": "p1"},
2020
]
21+
22+
@mock.patch("library.playback.links_open.make_souffle")
23+
@mock.patch("library.playback.links_open.play")
24+
def test_links_open_brackets(mock_play, mock_souffle, temp_db):
25+
db_path = temp_db()
26+
url = "https://example.com/test?page[]=107"
27+
lb(["links-add", "--no-extract", db_path, url])
28+
lb(["links-open", db_path, "-s", url])
29+
30+
assert mock_souffle.called
31+
media = mock_souffle.call_args[0][1]
32+
assert len(media) == 1
33+
assert media[0]["path"] == url

tests/playback/test_play_actions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
("--downloaded-before '1 day'", 0, ""),
2121
("--limit 1", 1, "corrupt.mp4"),
2222
("-L 1", 1, "corrupt.mp4"),
23-
("--online-media-only", 1, "https://test/?tags%5B%5D="),
24-
("--no-fts -s https://test/?tags%5B%5D=", 1, "https://test/?tags%5B%5D="),
25-
("--no-fts -s https://test/?tags[]=", 1, "https://test/?tags%5B%5D="),
26-
("--no-url-encode-search --no-fts -s https://test/?tags%5B%5D=", 1, "https://test/?tags%5B%5D="),
27-
("--no-url-encode-search --no-fts -s https://test/?tags[]=", 0, ""),
23+
("--online-media-only", 1, "https://test/?tags[]="),
24+
("--no-fts -s https://test/?tags[]=", 1, "https://test/?tags[]="),
25+
("--no-fts -s https://test/?tags%5B%5D=", 1, "https://test/?tags[]="),
26+
("--no-url-encode-search --no-fts -s https://test/?tags[]=", 1, "https://test/?tags[]="),
27+
("--no-url-encode-search --no-fts -s https://test/?tags%5B%5D=", 0, ""),
2828
("--offset 1", 4, "test.mp4"),
2929
("-s tests -s 'tests AND data' -E 2 -s test -E 3", 4, "corrupt.mp4"),
3030
("--created-within '30 years'", 5, "corrupt.mp4"),
@@ -83,7 +83,7 @@
8383
("-O duration", 5, "test.gif"),
8484
("-O locale_duration", 5, "test.gif"),
8585
("-O locale_size", 5, "test_frame.gif"),
86-
("-O reverse_path_path", 5, "https://test/?tags%5B%5D="),
86+
("-O reverse_path_path", 5, "https://test/?tags[]="),
8787
("-O size", 5, "test_frame.gif"),
8888
("-w time_deleted=0", 5, "corrupt.mp4"),
8989
]

tests/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def get_default_args(*funcs):
7070
v_db = p("tests/data/video.db")
7171
if not Path(v_db).exists():
7272
lb(["fs-add", v_db, "--scan-subtitles", p("tests/data/"), "-E", "Youtube"])
73-
lb(["links-db", v_db, "--insert-only", "https://test/?tags%5B%5D="])
73+
lb(["links-db", v_db, "--insert-only", "https://test/?tags[]="])
7474

7575

7676
tube_db = p("tests/data/tube.db")

0 commit comments

Comments
 (0)