@@ -87,7 +87,13 @@ def _build_url(self, path: str) -> str:
8787 normalized_query_suffix = (
8888 f"?{ normalized_parts .query } " if normalized_parts .query else ""
8989 )
90- parsed_base_url = urlparse (self .config .base_url )
90+ if not isinstance (self .config .base_url , str ):
91+ raise HyperbrowserError ("base_url must be a string" )
92+ normalized_base_url = self .config .base_url .strip ().rstrip ("/" )
93+ if not normalized_base_url :
94+ raise HyperbrowserError ("base_url must not be empty" )
95+
96+ parsed_base_url = urlparse (normalized_base_url )
9197 if (
9298 parsed_base_url .scheme not in {"https" , "http" }
9399 or not parsed_base_url .netloc
@@ -104,15 +110,15 @@ def _build_url(self, path: str) -> str:
104110 if normalized_path_only == "/api" or normalized_path_only .startswith ("/api/" ):
105111 if base_has_api_suffix :
106112 deduped_path = normalized_path_only [len ("/api" ) :]
107- return f"{ self . config . base_url } { deduped_path } { normalized_query_suffix } "
113+ return f"{ normalized_base_url } { deduped_path } { normalized_query_suffix } "
108114 return (
109- f"{ self . config . base_url } { normalized_path_only } { normalized_query_suffix } "
115+ f"{ normalized_base_url } { normalized_path_only } { normalized_query_suffix } "
110116 )
111117
112118 if base_has_api_suffix :
113119 return (
114- f"{ self . config . base_url } { normalized_path_only } { normalized_query_suffix } "
120+ f"{ normalized_base_url } { normalized_path_only } { normalized_query_suffix } "
115121 )
116122 return (
117- f"{ self . config . base_url } /api{ normalized_path_only } { normalized_query_suffix } "
123+ f"{ normalized_base_url } /api{ normalized_path_only } { normalized_query_suffix } "
118124 )
0 commit comments