File tree 2 files changed +23
-2
lines changed
packages/runtime/src/helpers
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ const sanitizeName = (name: string) => `next_${name.replace(/\W/g, '_')}`
96
96
/**
97
97
* Convert the images path to strip the origin (until domain-level Edge functions are supported)
98
98
*/
99
- const sanitizeEdgePath = ( imagesPath : string ) => new URL ( imagesPath , process . env . URL || 'http://n' ) . pathname
99
+ export const sanitizeEdgePath = ( imagesPath : string ) => new URL ( imagesPath , process . env . URL || 'http://n' ) . pathname
100
100
101
101
// Slightly different spacing in different versions!
102
102
const IMPORT_UNSUPPORTED = [
Original file line number Diff line number Diff line change 1
- import { getEdgeFunctionPatternForPage } from '../../packages/runtime/src/helpers/edge'
1
+ import { getEdgeFunctionPatternForPage , sanitizeEdgePath } from '../../packages/runtime/src/helpers/edge'
2
2
import { makeLocaleOptional , stripLookahead } from '../../packages/runtime/src/helpers/matchers'
3
3
4
4
const makeDataPath = ( path : string ) => `/_next/data/build-id${ path === '/' ? '/index' : path } .json`
@@ -183,3 +183,24 @@ describe('the edge function matcher helpers', () => {
183
183
expect ( '/edge/1/' ) . toMatch ( new RegExp ( regex ) )
184
184
} )
185
185
} )
186
+
187
+ describe ( 'the images path is sanitized' , ( ) => {
188
+ it ( 'passes through a path' , ( ) => {
189
+ expect ( sanitizeEdgePath ( '/_next/image' ) ) . toBe ( '/_next/image' )
190
+ } )
191
+
192
+ it ( 'strips domains' , ( ) => {
193
+ expect ( sanitizeEdgePath ( 'http://example.com/_next/image' ) ) . toBe ( '/_next/image' )
194
+ expect ( sanitizeEdgePath ( 'https://example.com/_next/image' ) ) . toBe ( '/_next/image' )
195
+ } )
196
+
197
+ it ( 'strips domains with globs' , ( ) => {
198
+ expect ( sanitizeEdgePath ( 'http://example.com/_next/image/*' ) ) . toBe ( '/_next/image/*' )
199
+ expect ( sanitizeEdgePath ( 'https://example.com/_next/image/*' ) ) . toBe ( '/_next/image/*' )
200
+ } )
201
+
202
+ it ( 'strips domains with tokens' , ( ) => {
203
+ expect ( sanitizeEdgePath ( 'http://example.com/_next/image/:slug/' ) ) . toBe ( '/_next/image/:slug/' )
204
+ expect ( sanitizeEdgePath ( 'https://example.com/_next/image/:slug/' ) ) . toBe ( '/_next/image/:slug/' )
205
+ } )
206
+ } )
You can’t perform that action at this time.
0 commit comments