Skip to content

Commit ba7e85d

Browse files
committed
fix
1 parent 47b2351 commit ba7e85d

File tree

1 file changed

+8
-8
lines changed
  • packages/cloudflare/src/cli/templates

1 file changed

+8
-8
lines changed

packages/cloudflare/src/cli/templates/images.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export function fetchImage(fetcher: Fetcher | undefined, imageUrl: string) {
4141
return getUrlErrorResponse();
4242
}
4343

44+
// If localPatterns are not defined all local images are allowed.
45+
if (__IMAGES_LOCAL_PATTERNS__.length === 0) {
46+
return fetcher?.fetch(`http://assets.local${imageUrl}`);
47+
}
48+
4449
if (!__IMAGES_LOCAL_PATTERNS__.some((p: LocalPattern) => matchLocalPattern(p, url))) {
4550
return getUrlErrorResponse();
4651
}
@@ -60,6 +65,7 @@ export function fetchImage(fetcher: Fetcher | undefined, imageUrl: string) {
6065
return getUrlErrorResponse();
6166
}
6267

68+
// The remotePatterns is used to allow images from specific remote external paths and block all others.
6369
if (!__IMAGES_REMOTE_PATTERNS__.some((p: RemotePattern) => matchRemotePattern(p, url))) {
6470
return getUrlErrorResponse();
6571
}
@@ -98,17 +104,11 @@ export function matchRemotePattern(pattern: RemotePattern, url: URL): boolean {
98104

99105
export function matchLocalPattern(pattern: LocalPattern, url: URL): boolean {
100106
// https://github.com/vercel/next.js/blob/d76f0b1/packages/next/src/shared/lib/match-local-pattern.ts
101-
if (pattern.search !== undefined) {
102-
if (pattern.search !== url.search) {
103-
return false;
104-
}
105-
}
106-
107-
if (!new RegExp(pattern.pathname).test(url.pathname)) {
107+
if (pattern.search !== undefined && pattern.search !== url.search) {
108108
return false;
109109
}
110110

111-
return true;
111+
return new RegExp(pattern.pathname).test(url.pathname);
112112
}
113113

114114
/**

0 commit comments

Comments
 (0)