Skip to content

Commit 3c78778

Browse files
authored
Merge pull request #100 from JohnJamesUtley/fix_fragment_cutoff
Stopped abnf regex from halting when it encounters a line terminator in the fragment
2 parents dda8bea + 1046724 commit 3c78778

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ 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(
138+
self, uri_fragment_with_line_terminators
139+
):
140+
"""Test that self.test_class encodes line terminators in the fragment properly"""
141+
ref = self.test_class.from_string(
142+
uri_fragment_with_line_terminators, "utf-8"
143+
)
144+
assert ref.fragment == "%0Afrag%0Ament%0A"
145+
137146

138147
class BaseTestUnsplits:
139148
test_class = None

tests/conftest.py

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

148148

149+
@pytest.fixture(params=valid_hosts)
150+
def uri_fragment_with_line_terminators(request):
151+
return "https://%s#\nfrag\nment\n" % request.param
152+
153+
149154
@pytest.fixture(params=equivalent_schemes)
150155
def scheme_only(request):
151156
return "%s:" % request.param

0 commit comments

Comments
 (0)