File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,6 +88,13 @@ def _build_url(self, path: str) -> str:
8888 raise HyperbrowserError ("path must be a relative API path" )
8989 if parsed_path .fragment :
9090 raise HyperbrowserError ("path must not include URL fragments" )
91+ if any (
92+ character .isspace () or ord (character ) < 32 or ord (character ) == 127
93+ for character in parsed_path .query
94+ ):
95+ raise HyperbrowserError (
96+ "path query must not contain unencoded whitespace or control characters"
97+ )
9198 normalized_path = f"/{ stripped_path .lstrip ('/' )} "
9299 normalized_parts = urlparse (normalized_path )
93100 normalized_path_only = normalized_parts .path
Original file line number Diff line number Diff line change @@ -321,6 +321,16 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
321321 HyperbrowserError , match = "path must not contain encoded fragment delimiters"
322322 ):
323323 client ._build_url ("/api/%23segment" )
324+ with pytest .raises (
325+ HyperbrowserError ,
326+ match = "path query must not contain unencoded whitespace or control characters" ,
327+ ):
328+ client ._build_url ("/session?foo=bar baz" )
329+ with pytest .raises (
330+ HyperbrowserError ,
331+ match = "path query must not contain unencoded whitespace or control characters" ,
332+ ):
333+ client ._build_url ("/session?foo=bar\x00 baz" )
324334 nested_encoded_segment = "%2e"
325335 for _ in range (11 ):
326336 nested_encoded_segment = quote (nested_encoded_segment , safe = "" )
You can’t perform that action at this time.
0 commit comments