@@ -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
99105export 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