Skip to content

Commit

Permalink
Merge pull request #100 from JohnJamesUtley/fix_fragment_cutoff
Browse files Browse the repository at this point in the history
Stopped abnf regex from halting when it encounters a line terminator in the fragment
  • Loading branch information
sigmavirus24 committed May 18, 2023
2 parents dda8bea + 1046724 commit 3c78778
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rfc3986/abnf_regexp.py
Expand Up @@ -42,7 +42,7 @@
_AUTHORITY_RE = "[^\\\\/?#]*"
_PATH_RE = "[^?#]*"
_QUERY_RE = "[^#]*"
_FRAGMENT_RE = ".*"
_FRAGMENT_RE = "(?s:.*)"

# Extracted from http://tools.ietf.org/html/rfc3986#appendix-B
COMPONENT_PATTERN_DICT = {
Expand Down
9 changes: 9 additions & 0 deletions tests/base.py
Expand Up @@ -134,6 +134,15 @@ def test_handles_percent_in_fragment(self, uri_fragment_with_percent):
uri = self.test_class.from_string(uri_fragment_with_percent)
assert uri.fragment == "perc%25ent"

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


class BaseTestUnsplits:
test_class = None
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Expand Up @@ -146,6 +146,11 @@ def uri_fragment_with_percent(request):
return "https://%s#perc%%ent" % request.param


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


@pytest.fixture(params=equivalent_schemes)
def scheme_only(request):
return "%s:" % request.param
Expand Down

0 comments on commit 3c78778

Please sign in to comment.