44import inspect
55import re
66from typing import Any , Callable
7- from urllib .parse import urlparse
7+ from urllib .parse import urlparse , ParseResult
88
99from starlette .datastructures import QueryParams
1010from typing_extensions import Self
@@ -147,6 +147,7 @@ def _reset_match(self) -> None:
147147
148148 def _find_matching_path (self ) -> RouteMatch | None :
149149 match : RouteMatch | None = None
150+ query_params : QueryParams | None = None
150151 relative_path = self ._router .current_path [len (self ._root_path or '' ):]
151152 if not relative_path .startswith ('/' ):
152153 relative_path = '/' + relative_path
@@ -155,17 +156,22 @@ def _find_matching_path(self) -> RouteMatch | None:
155156 path = '/' .join (segments )
156157 if not path :
157158 path = '/'
158- match = self ._match_route (path )
159+ parsed_url = urlparse (path )
160+
161+ if query_params is None and parsed_url .query :
162+ query_params = QueryParams (parsed_url .query )
163+
164+ match = self ._match_route (parsed_url , query_params )
159165 if match is not None :
160166 match .remaining_path = urlparse (relative_path ).path .rstrip ('/' )[len (match .path ):]
161167 break
162168 segments .pop ()
163169 return match
164170
165- def _match_route (self , path : str ) -> RouteMatch | None :
166- parsed_url = urlparse (path )
171+ def _match_route (self , parsed_url : ParseResult , query_params : QueryParams | None ) -> RouteMatch | None :
167172 path_only = parsed_url .path .rstrip ('/' )
168- query_params = QueryParams (parsed_url .query ) if parsed_url .query else QueryParams ()
173+ if query_params is None :
174+ query_params = QueryParams (parsed_url .query ) if parsed_url .query else QueryParams ()
169175 fragment = parsed_url .fragment
170176 if not path_only .startswith ('/' ):
171177 path_only = '/' + path_only
0 commit comments