Skip to content

Commit

Permalink
fix: obj/url: normalize http but not other schemes, detect http non-s…
Browse files Browse the repository at this point in the history
…tandard casing
  • Loading branch information
jimmy-zhening-luo committed Jan 23, 2025
1 parent cefab23 commit 336fb96
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/object/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ export default function (
fragment = "",
} = (/^(?:(?<scheme>[^:/?#]+):)?(?:\/\/(?<host>[^/?#]*))?(?<path>[^?#]*)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?/u)
.exec(string)?.groups ?? {},
http = ["https", "http"].includes(scheme);
http = ["https", "http"].includes(scheme.toLocaleLowerCase());

return scheme === "" || http && !host.includes(".")
? null
: {
scheme: (http && omitHttp ? "" : scheme.toLocaleLowerCase()) as stringfully<"URL: scheme || host">,
scheme: (http
? omitHttp
? ""
: "https"
: scheme) as stringfully<"URL: scheme || host">,
host: host.toLocaleLowerCase() as stringfully<"URL: scheme || host">,
path,
query,
Expand Down

0 comments on commit 336fb96

Please sign in to comment.