Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/fetch/src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ test("patternMatchesHostname with wildcard domains", () => {
test("patternMatchesHostname with domain suffix", () => {
expect(patternMatchesHostname("sub.example.com", ".example.com")).toBe(true);
expect(patternMatchesHostname("example.com", ".example.com")).toBe(true);
expect(patternMatchesHostname("badexample.com", ".example.com")).toBe(false);
expect(patternMatchesHostname("different.com", ".example.com")).toBe(false);
});

Expand Down Expand Up @@ -121,6 +122,9 @@ test("patternMatchesHostname with domain suffix and ports", () => {
expect(patternMatchesHostname("example.com:8080", ".example.com:8080")).toBe(
true,
);
expect(
patternMatchesHostname("badexample.com:8080", ".example.com:8080"),
).toBe(false);
expect(
patternMatchesHostname("sub.example.com:9090", ".example.com:8080"),
).toBe(false);
Expand Down Expand Up @@ -157,6 +161,7 @@ test("shouldBypassProxy works with domain suffix", () => {
process.env.NO_PROXY = ".example.com";
expect(shouldBypassProxy("sub.example.com", undefined)).toBe(true);
expect(shouldBypassProxy("example.com", undefined)).toBe(true);
expect(shouldBypassProxy("badexample.com", undefined)).toBe(false);
expect(shouldBypassProxy("different.com", undefined)).toBe(false);
});

Expand All @@ -166,6 +171,7 @@ test("shouldBypassProxy handles multiple entries with different patterns", () =>
expect(shouldBypassProxy("sub.example.com", undefined)).toBe(true);
expect(shouldBypassProxy("sub.test.com", undefined)).toBe(true);
expect(shouldBypassProxy("test.com", undefined)).toBe(true);
expect(shouldBypassProxy("contest.com", undefined)).toBe(false);
expect(shouldBypassProxy("example.org", undefined)).toBe(false);
});

Expand All @@ -182,6 +188,7 @@ test("shouldBypassProxy with ports in NO_PROXY", () => {
expect(shouldBypassProxy("sub.test.org:443", undefined)).toBe(true);
expect(shouldBypassProxy("sub.internal.net:8443", undefined)).toBe(true);
expect(shouldBypassProxy("internal.net:8443", undefined)).toBe(true);
expect(shouldBypassProxy("notinternal.net:8443", undefined)).toBe(false);
});

test("shouldBypassProxy accepts options with noProxy patterns", () => {
Expand Down
13 changes: 8 additions & 5 deletions packages/fetch/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ export function patternMatchesHostname(hostname: string, pattern: string) {
return true;
}
// Domain suffix match (.example.com)
if (
patternWithoutPort.startsWith(".") &&
hostnameWithoutPort.endsWith(patternWithoutPort.slice(1))
) {
return true;
if (patternWithoutPort.startsWith(".")) {
const suffixWithoutDot = patternWithoutPort.slice(1);
if (
hostnameWithoutPort === suffixWithoutDot ||
hostnameWithoutPort.endsWith(patternWithoutPort)
) {
return true;
}
}

// TODO IP address ranges
Expand Down
Loading