@@ -26,26 +26,27 @@ class ResourceMapper {
2626
2727 // Maps the request for a given resource and representation format to a server file
2828 async mapUrlToFile ( { url, contentType, createIfNotExists } ) {
29- // Split the URL into components
29+ // Determine the full URL
3030 const { pathname, hostname } = typeof url === 'string' ? URL . parse ( url ) : url
31- if ( pathname . indexOf ( '/..' ) >= 0 ) {
31+ const fullPath = decodeURIComponent ( `${ this . getBasePath ( hostname ) } ${ pathname } ` )
32+ if ( fullPath . indexOf ( '/..' ) >= 0 ) {
3233 throw new Error ( 'Disallowed /.. segment in URL' )
3334 }
3435
36+ // Determine the path and content type
3537 let path
36- const basePath = this . getBasePath ( hostname )
37- // Create the path for a new file
3838 if ( createIfNotExists ) {
39- path = `${ basePath } ${ pathname } `
39+ // Create the path for a new file
40+ path = fullPath
4041 // If the extension is not correct for the content type, append the correct extension
41- if ( getContentType ( pathname ) !== contentType ) {
42+ if ( getContentType ( path ) !== contentType ) {
4243 path += contentType in extensions ? `$.${ extensions [ contentType ] [ 0 ] } ` : '$.unknown'
4344 }
4445 // Determine the path of an existing file
4546 } else {
4647 // Read all files in the corresponding folder
47- const filename = pathname . substr ( pathname . lastIndexOf ( '/' ) + 1 )
48- const folder = ` ${ basePath } ${ pathname . substr ( 0 , pathname . length - filename . length ) } `
48+ const filename = fullPath . substr ( fullPath . lastIndexOf ( '/' ) + 1 )
49+ const folder = fullPath . substr ( 0 , fullPath . length - filename . length )
4950 const files = await this . _readdir ( folder )
5051
5152 // Find a file with the same name (minus the dollar extension)
@@ -64,7 +65,7 @@ class ResourceMapper {
6465 async mapFileToUrl ( { path, hostname } ) {
6566 // Determine the URL by chopping off everything after the dollar sign
6667 const pathname = removeDollarExtension ( path . substring ( this . _rootPath . length ) )
67- const url = `${ this . getBaseUrl ( hostname ) } ${ pathname } `
68+ const url = `${ this . getBaseUrl ( hostname ) } ${ encodeURI ( pathname ) } `
6869 return { url, contentType : getContentType ( path ) }
6970 }
7071
0 commit comments