File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Fixed the C HTTP parser folding the fragment into the query string for an
2+ origin-form request target with an empty query (e.g. ``/path?#frag ``),
3+ which diverged from the pure-Python parser -- by :user: `GiulioDER `.
Original file line number Diff line number Diff line change @@ -734,7 +734,7 @@ cdef class HttpRequestParser(HttpParser):
734734 else :
735735 path = self ._path[0 :idx1]
736736 idx1 += 1
737- idx2 = self ._path.find(" #" , idx1+ 1 )
737+ idx2 = self ._path.find(" #" , idx1)
738738 if idx2 == - 1 :
739739 query = self ._path[idx1:]
740740 fragment = " "
Original file line number Diff line number Diff line change @@ -2411,6 +2411,19 @@ def test_parse_uri_utf8_percent_encoded(parser) -> None:
24112411 assert msg .url .fragment == "фраг"
24122412
24132413
2414+ def test_parse_uri_empty_query_with_fragment (parser : HttpRequestParser ) -> None :
2415+ # Origin-form target with an empty query but a fragment: the ``#`` sits
2416+ # immediately after ``?``. Regression for the C parser folding ``#frag``
2417+ # into the query string instead of the fragment.
2418+ text = b"GET /path?#frag HTTP/1.1\r \n Host: a\r \n \r \n "
2419+ messages , upgrade , tail = parser .feed_data (text )
2420+ msg = messages [0 ][0 ]
2421+
2422+ assert msg .url .path == "/path"
2423+ assert msg .url .query == {}
2424+ assert msg .url .fragment == "frag"
2425+
2426+
24142427@pytest .mark .skipif (
24152428 "HttpRequestParserC" not in dir (aiohttp .http_parser ),
24162429 reason = "C based HTTP parser not available" ,
You can’t perform that action at this time.
0 commit comments