diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index dad049d335..1c9c39c9e5 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -5,6 +5,7 @@ import React from 'react' // eslint-disable-line import ReactDOM from 'react-dom' import { Workspace } from '@remix-ui/workspace' // eslint-disable-line import * as ethutil from 'ethereumjs-util' +import { checkSpecialChars, checkSlash } from '../../lib/helper' var EventManager = require('../../lib/events') var { RemixdHandle } = require('../files/remixd-handle.js') var { GitHandle } = require('../files/git-handle.js') @@ -186,6 +187,8 @@ module.exports = class Filepanel extends ViewPlugin { } async createWorkspace (workspaceName) { + if (!workspaceName) throw new Error('name cannot be empty') + if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists') const browserProvider = this._deps.fileProviders.browser const workspacesPath = this._deps.fileProviders.workspace.workspacesPath diff --git a/apps/remix-ide/src/lib/helper.js b/apps/remix-ide/src/lib/helper.js index a96b8b0256..ac3f71a0e5 100644 --- a/apps/remix-ide/src/lib/helper.js +++ b/apps/remix-ide/src/lib/helper.js @@ -55,6 +55,9 @@ module.exports = { checkSpecialChars (name) { return name.match(/[:*?"<>\\'|]/) != null }, + checkSlash (name) { + return name.match(/\//) != null + }, isHexadecimal (value) { return /^[0-9a-fA-F]+$/.test(value) && (value.length % 2 === 0) }, diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index d56c278791..32916ebc6a 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -181,11 +181,11 @@ export const Workspace = (props: WorkspaceProps) => { try { await props.createWorkspace(workspaceName) + await setWorkspace(workspaceName) } catch (e) { modalMessage('Workspace Creation', e.message) console.error(e) } - await setWorkspace(workspaceName) } const onFinishDeleteWorkspace = async () => {