diff --git a/src/rfc3986/abnf_regexp.py b/src/rfc3986/abnf_regexp.py index 7220e46..899b7b5 100644 --- a/src/rfc3986/abnf_regexp.py +++ b/src/rfc3986/abnf_regexp.py @@ -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 = { diff --git a/tests/base.py b/tests/base.py index 03ead71..6e3f7a1 100644 --- a/tests/base.py +++ b/tests/base.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 62db168..3b2f871 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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