Skip to content

Commit 51ed4c9

Browse files
Stops abnf regex from halting when it encounters a line terminator in the fragment
1 parent dda8bea commit 51ed4c9

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/rfc3986/abnf_regexp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
_AUTHORITY_RE = "[^\\\\/?#]*"
4343
_PATH_RE = "[^?#]*"
4444
_QUERY_RE = "[^#]*"
45-
_FRAGMENT_RE = ".*"
45+
_FRAGMENT_RE = "(?s:.*)"
4646

4747
# Extracted from http://tools.ietf.org/html/rfc3986#appendix-B
4848
COMPONENT_PATTERN_DICT = {

tests/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ def test_handles_percent_in_fragment(self, uri_fragment_with_percent):
134134
uri = self.test_class.from_string(uri_fragment_with_percent)
135135
assert uri.fragment == "perc%25ent"
136136

137+
def test_handles_line_terminators_in_fragment(self, uri_fragment_with_line_terminators):
138+
"""Test that self.test_class encodes line terminators in the fragment properly"""
139+
ref = self.test_class.from_string(uri_fragment_with_line_terminators, 'utf-8')
140+
assert ref.fragment == "%0Afrag%0Ament%0A"
137141

138142
class BaseTestUnsplits:
139143
test_class = None

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def uri_query_with_percent(request):
145145
def uri_fragment_with_percent(request):
146146
return "https://%s#perc%%ent" % request.param
147147

148+
@pytest.fixture(params=valid_hosts)
149+
def uri_fragment_with_line_terminators(request):
150+
return "https://%s#\nfrag\nment\n" % request.param
148151

149152
@pytest.fixture(params=equivalent_schemes)
150153
def scheme_only(request):

0 commit comments

Comments
 (0)