Skip to content

Commit aa69aef

Browse files
committed
Abstract away non-JS code
1 parent 9b92509 commit aa69aef

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

playwright/_impl/_helper.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,25 +216,29 @@ def map_token(original: str, replacement: str) -> str:
216216
for replacement, original in token_map.items():
217217
resolved_url = resolved_url.replace(replacement, original, 1)
218218

219-
# In Node.js, new URL('http://localhost') returns 'http://localhost/'.
220-
# To ensure the same url matching behavior, do the same.
221-
split = resolved_url.split("://", maxsplit=1)
219+
return ensure_trailing_slash(resolved_url)
220+
221+
222+
# In Node.js, new URL('http://localhost') returns 'http://localhost/'.
223+
# To ensure the same url matching behavior, do the same.
224+
def ensure_trailing_slash(url: str) -> str:
225+
split = url.split("://", maxsplit=1)
222226
if len(split) == 2:
223227
# URL parser doesn't like strange/unknown schemes, so we replace it for parsing, then put it back
224228
parsable_url = "http://" + split[1]
225229
else:
226230
# Given current rules, this should never happen _and_ still be a valid matcher. We require the protocol to be part of the match,
227231
# so either the user is using a glob that starts with "*" (and none of this code is running), or the user actually has `something://` in `match`
228-
parsable_url = resolved_url
232+
parsable_url = url
229233
parsed = urlparse(parsable_url, allow_fragments=True)
230234
if len(split) == 2:
231235
# Replace the scheme that we removed earlier
232236
parsed = parsed._replace(scheme=split[0])
233237
if parsed.path == "":
234238
parsed = parsed._replace(path="/")
235-
resolved_url = parsed.geturl()
239+
url = parsed.geturl()
236240

237-
return resolved_url
241+
return url
238242

239243

240244
class HarLookupResult(TypedDict, total=False):

0 commit comments

Comments
 (0)