Skip to content

Commit 531de2b

Browse files
authored
Match URL paths containing an equal sign (#82)
1 parent d8ec583 commit 531de2b

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/protego/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _quote_path(path: str) -> str:
5858
"""Return percent encoded path."""
5959
parts = urlparse(path)
6060
path = _unquote(parts.path, ignore="/%")
61-
path = quote(path, safe="/%")
61+
path = quote(path, safe="/%=")
6262

6363
parts = ParseResult("", "", path, parts.params, parts.query, parts.fragment)
6464
path = urlunparse(parts)

tests/test_protego.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,20 @@ def test_disallow_query_wildcard(self):
13571357
assert not rp.can_fetch("https://www.site.local/?s=asd", "*")
13581358

13591359

1360+
@pytest.mark.parametrize(
1361+
("url", "allowed"),
1362+
[
1363+
("https://example.com/1/filter/page=5/", True),
1364+
("https://example.com/1/filter/page%3D5/", True),
1365+
("https://example.com/1/filter/page=5/x", False),
1366+
],
1367+
)
1368+
def test_equal_sign_in_path(url, allowed):
1369+
content = "User-agent: *\nAllow: /*/filter/page=*/$\nDisallow: /\n"
1370+
rp = Protego.parse(content)
1371+
assert rp.can_fetch(url, "*") == allowed
1372+
1373+
13601374
@pytest.mark.parametrize(
13611375
("allow", "disallow", "url", "allowed"),
13621376
[

0 commit comments

Comments
 (0)