Skip to content

Commit 98fcfcc

Browse files
author
Martin Skovvang Petersen
committed
Support blank lines between group directives
1 parent 237d89e commit 98fcfcc

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

robotstxtparser/robotstxtparser.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,7 @@ def parse(self, s):
556556
line = line.strip()
557557

558558
if not line:
559-
# An empty line indicates the end of a ruleset.
560-
if current_ruleset and current_ruleset.is_not_empty():
561-
self.__rulesets.append(current_ruleset)
562-
563-
current_ruleset = None
564-
previous_line_was_a_user_agent = False
559+
pass
565560
else:
566561
# Each non-empty line falls into one of six categories:
567562
# 1) User-agent: blah blah blah

tests/test_robots.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_skip_malformed_line(self):
7777
self.assertTrue(rp.is_allowed('agent', 'http://example.org/no/colon/in/this/line'))
7878

7979
def test_utf8_bom(self):
80-
"""If there's a utf-8 BOM, we should parse it as such"""
80+
"""If there's a UTF-8 BOM, we should parse it as such"""
8181
rp = robotstxtparser.RobotExclusionRulesParser()
8282
rp.parse(codecs.BOM_UTF8 + b'''
8383
User-Agent: agent
@@ -163,3 +163,21 @@ def test_rfc_example(self):
163163
self.assertFalse(rp.is_allowed('anything', 'http://example.org/%7Ejim/jim.html'))
164164
self.assertTrue(rp.is_allowed('anything', 'http://example.org/%7Emak/mak.html'))
165165

166+
def test_support_grouping_blank_lines(self):
167+
"""Make sure blank lines are ignored"""
168+
rp = robotstxtparser.RobotExclusionRulesParser()
169+
rp.parse('''
170+
User-Agent: agent
171+
172+
Allow: /path
173+
174+
Disallow: /tmp
175+
176+
User-Agent: other
177+
178+
Disallow: /path
179+
''')
180+
181+
self.assertTrue(rp.is_allowed('agent', 'http://example.org/path'))
182+
self.assertFalse(rp.is_allowed('agent', 'http://example.org/tmp'))
183+
self.assertFalse(rp.is_allowed('other', 'http://example.org/path'))

0 commit comments

Comments
 (0)