add more check during workspace creattion

pull/933/head
yann300 4 years ago
parent 0667661a4f
commit 814c12ff3d
  1. 3
      apps/remix-ide/src/app/panels/file-panel.js
  2. 3
      apps/remix-ide/src/lib/helper.js
  3. 2
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -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

@ -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)
},

@ -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 () => {

Loading…
Cancel
Save