@@ -164,13 +164,22 @@ function extractShareLinkData(
164164 return shareLinkInfo ;
165165}
166166
167+ /**
168+ * Encodes file path so it can be embedded in the request url
169+ * @param path - path to encode
170+ * @returns encoded path or "" if path is undefined
171+ */
172+ function encodeFilePath ( path : string | undefined ) : string {
173+ return path ? encodeURIComponent ( path . startsWith ( "/" ) ? path : `/${ path } ` ) : "" ;
174+ }
175+
167176export async function createNewEmptyFluidFile (
168177 getAuthHeader : InstrumentedStorageTokenFetcher ,
169178 newFileInfo : INewFileInfo ,
170179 logger : ITelemetryLoggerExt ,
171180 epochTracker : EpochTracker ,
172181) : Promise < string > {
173- const filePath = newFileInfo . filePath ? encodeURIComponent ( `/ ${ newFileInfo . filePath } ` ) : "" ;
182+ const filePath = encodeFilePath ( newFileInfo . filePath ) ;
174183 // add .tmp extension to empty file (host is expected to rename)
175184 const encodedFilename = encodeURIComponent ( `${ newFileInfo . filename } .tmp` ) ;
176185 const initialUrl = `${ getApiRoot ( new URL ( newFileInfo . siteUrl ) ) } /drives/${
@@ -234,7 +243,7 @@ export async function createNewFluidFileFromSummary(
234243 epochTracker : EpochTracker ,
235244 forceAccessTokenViaAuthorizationHeader : boolean ,
236245) : Promise < ICreateFileResponse > {
237- const filePath = newFileInfo . filePath ? encodeURIComponent ( `/ ${ newFileInfo . filePath } ` ) : "" ;
246+ const filePath = encodeFilePath ( newFileInfo . filePath ) ;
238247 const encodedFilename = encodeURIComponent ( newFileInfo . filename ) ;
239248 const baseUrl =
240249 `${ getApiRoot ( new URL ( newFileInfo . siteUrl ) ) } /drives/${ newFileInfo . driveId } /items/root:` +
0 commit comments