Skip to content

Commit 39d8a35

Browse files
[port 2.0]: Avoid two leading slashes in the request to create a new file (#22588)
Cherry-pick: #22563 Co-authored-by: Andrew Boktor <[email protected]>
1 parent 97f5096 commit 39d8a35

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/drivers/odsp-driver/src/createFile.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
167176
export 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

Comments
 (0)