Commit ad47b45d authored by yann300's avatar yann300

renaming, tes special character

parent d3b93057
...@@ -22,6 +22,10 @@ export interface WorkspaceProps { ...@@ -22,6 +22,10 @@ export interface WorkspaceProps {
initialWorkspace: string initialWorkspace: string
} }
const hasSpecialChar = (value) => {
return value.match(/[:*?"<>\\'|]/) != null || value.match(/\//) != null
}
var canUpload = window.File || window.FileReader || window.FileList || window.Blob var canUpload = window.File || window.FileReader || window.FileList || window.Blob
export const Workspace = (props: WorkspaceProps) => { export const Workspace = (props: WorkspaceProps) => {
const LOCALHOST = ' - connect to localhost - ' const LOCALHOST = ' - connect to localhost - '
...@@ -152,10 +156,12 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -152,10 +156,12 @@ export const Workspace = (props: WorkspaceProps) => {
} }
const modalMessage = (title: string, body: string) => { const modalMessage = (title: string, body: string) => {
modal(title, body, { setTimeout(() => { // wait for any previous modal a chance to close
label: 'OK', modal(title, body, {
fn: () => {} label: 'OK',
}, null) fn: () => {}
}, null)
}, 200)
} }
const workspaceRenameInput = useRef() const workspaceRenameInput = useRef()
...@@ -165,6 +171,8 @@ export const Workspace = (props: WorkspaceProps) => { ...@@ -165,6 +171,8 @@ export const Workspace = (props: WorkspaceProps) => {
if (workspaceRenameInput.current === undefined) return if (workspaceRenameInput.current === undefined) return
// @ts-ignore: Object is possibly 'null'. // @ts-ignore: Object is possibly 'null'.
const workspaceName = workspaceRenameInput.current.value const workspaceName = workspaceRenameInput.current.value
if (hasSpecialChar(workspaceName)) return modalMessage('Workspace Rename', 'special characters are not allowed')
const workspacesPath = props.workspace.workspacesPath const workspacesPath = props.workspace.workspacesPath
await props.fileManager.rename('browser/' + workspacesPath + '/' + state.currentWorkspace, 'browser/' + workspacesPath + '/' + workspaceName) await props.fileManager.rename('browser/' + workspacesPath + '/' + state.currentWorkspace, 'browser/' + workspacesPath + '/' + workspaceName)
setWorkspace(workspaceName) setWorkspace(workspaceName)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment