Skip to content

Commit

Permalink
Merge pull request #19 from Laerte/fix/disallow-when-target-path-is-m…
Browse files Browse the repository at this point in the history
…issing

Fix disallow not working when no path is provided
  • Loading branch information
whalebot-helmsman authored Oct 7, 2021
2 parents 11ee491 + 6d9469e commit 2a10355
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/protego.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _quote_path(self, path):

parts = ParseResult('', '', path, parts.params, parts.query, parts.fragment)
path = urlunparse(parts)
return path
return path or '/'

def _quote_pattern(self, pattern):
# Corner case for query only (e.g. '/abc?') and param only (e.g. '/abc;') URLs.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_protego.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,3 +1053,9 @@ def test_sitemaps_come_first(self):
"Disallow: /something")
rp = Protego.parse(content=content)
self.assertEquals(list(rp.sitemaps), ["https://www.foo.bar/sitmap.xml"])

def test_disallow_target_url_path_is_missing(self):
content = "User-Agent: *\nDisallow: /\n"
rp = Protego.parse(content)
self.assertFalse(rp.can_fetch("http://example.com/", "FooBot"))
self.assertFalse(rp.can_fetch("http://example.com", "FooBot"))

0 comments on commit 2a10355

Please sign in to comment.