Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(joinRelativeURL): handle base with protocol #222

Merged
merged 5 commits into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/utils.ts
Expand Up @@ -14,6 +14,7 @@ const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
const PROTOCOL_SCRIPT_RE = /^[\s\0]*(blob|data|javascript|vbscript):$/i;
const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
const JOIN_LEADING_SLASH_RE = /^\.?\//;
const JOIN_SEGMENT_SPLIT_RE = /(?<!\/)\/(?!\/)/;

/**
* Check if a path starts with `./` or `../`.
Expand Down Expand Up @@ -355,7 +356,7 @@ export function joinRelativeURL(..._input: string[]): string {
if (!i || i === "/") {
continue;
}
for (const s of i.split("/")) {
for (const s of i.split(JOIN_SEGMENT_SPLIT_RE)) {
if (!s || s === ".") {
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions test/join.test.ts
Expand Up @@ -16,6 +16,10 @@ const joinURLTests = [
{ input: ["/", "./foo"], out: "/foo" },
{ input: ["/", "./foo/"], out: "/foo/" },
{ input: ["/", "./foo", "bar"], out: "/foo/bar" },
{
input: ["https://google.com/", "./foo", "/bar"],
out: "https://google.com/foo/bar",
},
pi0 marked this conversation as resolved.
Show resolved Hide resolved
] as const;

describe("joinURL", () => {
Expand Down