Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[port 2.3]: Avoid two leading slashes in the request to create a new file (#22563) #22591

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/drivers/odsp-driver/src/createFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,22 @@ function extractShareLinkData(
return shareLinkInfo;
}

/**
* Encodes file path so it can be embedded in the request url
* @param path - path to encode
* @returns encoded path or "" if path is undefined
*/
function encodeFilePath(path: string | undefined): string {
return path ? encodeURIComponent(path.startsWith("/") ? path : `/${path}`) : "";
}

export async function createNewEmptyFluidFile(
getAuthHeader: InstrumentedStorageTokenFetcher,
newFileInfo: INewFileInfo,
logger: ITelemetryLoggerExt,
epochTracker: EpochTracker,
): Promise<string> {
const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : "";
const filePath = encodeFilePath(newFileInfo.filePath);
// add .tmp extension to empty file (host is expected to rename)
const encodedFilename = encodeURIComponent(`${newFileInfo.filename}.tmp`);
const initialUrl = `${getApiRoot(new URL(newFileInfo.siteUrl))}/drives/${
Expand Down Expand Up @@ -234,7 +243,7 @@ export async function createNewFluidFileFromSummary(
epochTracker: EpochTracker,
forceAccessTokenViaAuthorizationHeader: boolean,
): Promise<ICreateFileResponse> {
const filePath = newFileInfo.filePath ? encodeURIComponent(`/${newFileInfo.filePath}`) : "";
const filePath = encodeFilePath(newFileInfo.filePath);
const encodedFilename = encodeURIComponent(newFileInfo.filename);
const baseUrl =
`${getApiRoot(new URL(newFileInfo.siteUrl))}/drives/${newFileInfo.driveId}/items/root:` +
Expand Down
Loading