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
@@ -149,6 +149,7 @@ def _reset_match(self) -> None:
149149
150150 def _find_matching_path (self ) -> RouteMatch | None :
151151 match : RouteMatch | None = None
152+ query_params : QueryParams | None = None
152153 relative_path = self ._router .current_path [len (self ._root_path or '' ):]
153154 if not relative_path .startswith ('/' ):
154155 relative_path = '/' + relative_path
@@ -157,17 +158,22 @@ def _find_matching_path(self) -> RouteMatch | None:
157158 path = '/' .join (segments )
158159 if not path :
159160 path = '/'
160- match = self ._match_route (path )
161+ parsed_url = urlparse (path )
162+
163+ if query_params is None and parsed_url .query :
164+ query_params = QueryParams (parsed_url .query )
165+
166+ match = self ._match_route (parsed_url , query_params )
161167 if match is not None :
162168 match .remaining_path = urlparse (relative_path ).path .rstrip ('/' )[len (match .path ):]
163169 break
164170 segments .pop ()
165171 return match
166172
167- def _match_route (self , path : str ) -> RouteMatch | None :
168- parsed_url = urlparse (path )
173+ def _match_route (self , parsed_url : ParseResult , query_params : QueryParams | None ) -> RouteMatch | None :
169174 path_only = parsed_url .path .rstrip ('/' )
170- query_params = QueryParams (parsed_url .query ) if parsed_url .query else QueryParams ()
175+ if query_params is None :
176+ query_params = QueryParams (parsed_url .query ) if parsed_url .query else QueryParams ()
171177 fragment = parsed_url .fragment
172178 if not path_only .startswith ('/' ):
173179 path_only = '/' + path_only
0 commit comments