Don't allow invalid names when mapping drive

This commit is contained in:
Dustin Brett
2022-08-12 22:12:12 -07:00
parent 1ff30f6b67
commit 927f7669f2
2 changed files with 9 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ import useAsyncFs from "contexts/fileSystem/useAsyncFs";
import type { UpdateFiles } from "contexts/session/types";
import { basename, dirname, extname, isAbsolute, join } from "path";
import { useCallback, useEffect, useState } from "react";
import { DEFAULT_MAPPED_NAME, INVALID_FILE_CHARACTERS } from "utils/constants";
type FilePasteOperations = Record<string, "copy" | "move">;
@@ -117,8 +118,12 @@ const useFileSystemContextState = (): FileSystemContextState => {
return;
}
rootFs?.mount?.(join(directory, handle.name), newFs);
resolve(handle.name);
const mappedName =
handle.name.replace(INVALID_FILE_CHARACTERS, "").trim() ||
DEFAULT_MAPPED_NAME;
rootFs?.mount?.(join(directory, mappedName), newFs);
resolve(mappedName);
addFileSystemHandle(directory, handle);
});
} else {

View File

@@ -19,6 +19,8 @@ export const DEFAULT_WINDOW_SIZE: Size = {
width: 405,
};
export const DEFAULT_MAPPED_NAME = "Share";
export const FOCUSABLE_ELEMENT = { tabIndex: -1 };
export const FS_HANDLES = "FileSystemAccessHandles";