From 63a878eb36ef95a262b8d96fc28aa6be1698c7cd Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 5 Oct 2017 21:53:58 +0200 Subject: [PATCH] check fo special char --- src/app.js | 7 ++++++- src/app/files/browser-files.js | 4 ++++ src/app/files/file-explorer.js | 6 +++++- src/app/files/shared-folder.js | 4 ++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index f888d9d52a..57aec5e3d2 100644 --- a/src/app.js +++ b/src/app.js @@ -369,7 +369,12 @@ function run () { // Add files received from remote instance (i.e. another browser-solidity) function loadFiles (filesSet) { for (var f in filesSet) { - filesProviders['browser'].set(helper.createNonClashingName(f, filesProviders['browser']), filesSet[f].content) + var name = helper.createNonClashingName(f, filesProviders['browser']) + if (filesProviders['browser'].checkSpecialChars(name)) { + modalDialogCustom.alert('Special characters are not allowed') + return + } + filesProviders['browser'].set(name, filesSet[f].content) } fileManager.switchFile() } diff --git a/src/app/files/browser-files.js b/src/app/files/browser-files.js index b14163a892..4068f1a1ef 100644 --- a/src/app/files/browser-files.js +++ b/src/app/files/browser-files.js @@ -22,6 +22,10 @@ function Files (storage) { cb() } + this.checkSpecialChars = function (name) { + return name.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) != null + } + this.get = function (path, cb) { var unprefixedpath = this.removePrefix(path) // NOTE: ignore the config file diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 28da9ceca8..338fea7f78 100755 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -137,6 +137,10 @@ function fileExplorer (appAPI, files) { function loadFile () { var fileReader = new FileReader() fileReader.onload = function (event) { + if (files.checkSpecialChars(name)) { + modalDialogCustom.alert('Special characters are not allowed') + return + } var success = files.set(name, event.target.result) if (!success) modalDialogCustom.alert('Failed to create file ' + name) else events.trigger('focus', [name]) @@ -228,7 +232,7 @@ function fileExplorer (appAPI, files) { if (label.innerText === '') { modalDialogCustom.alert('File name cannot be empty') label.innerText = textUnderEdit - } else if (label.innerText.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) !== null) { + } else if (files.checkSpecialChars(label.innerText)) { modalDialogCustom.alert('Special characters are not allowed') label.innerText = textUnderEdit } else if (!files.exists(newPath)) { diff --git a/src/app/files/shared-folder.js b/src/app/files/shared-folder.js index 3632e8e17a..54423095ce 100644 --- a/src/app/files/shared-folder.js +++ b/src/app/files/shared-folder.js @@ -45,6 +45,10 @@ class SharedFolder { cb() } + checkSpecialChars (name) { + return name.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) != null + } + init (cb) { this.remixd.call('sharedfolder', 'list', {}, (error, filesList) => { if (error) {