Commit 63a878eb authored by yann300's avatar yann300

check fo special char

parent 924f28c7
...@@ -369,7 +369,12 @@ function run () { ...@@ -369,7 +369,12 @@ function run () {
// Add files received from remote instance (i.e. another browser-solidity) // Add files received from remote instance (i.e. another browser-solidity)
function loadFiles (filesSet) { function loadFiles (filesSet) {
for (var f in 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() fileManager.switchFile()
} }
......
...@@ -22,6 +22,10 @@ function Files (storage) { ...@@ -22,6 +22,10 @@ function Files (storage) {
cb() cb()
} }
this.checkSpecialChars = function (name) {
return name.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) != null
}
this.get = function (path, cb) { this.get = function (path, cb) {
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
// NOTE: ignore the config file // NOTE: ignore the config file
......
...@@ -137,6 +137,10 @@ function fileExplorer (appAPI, files) { ...@@ -137,6 +137,10 @@ function fileExplorer (appAPI, files) {
function loadFile () { function loadFile () {
var fileReader = new FileReader() var fileReader = new FileReader()
fileReader.onload = function (event) { fileReader.onload = function (event) {
if (files.checkSpecialChars(name)) {
modalDialogCustom.alert('Special characters are not allowed')
return
}
var success = files.set(name, event.target.result) var success = files.set(name, event.target.result)
if (!success) modalDialogCustom.alert('Failed to create file ' + name) if (!success) modalDialogCustom.alert('Failed to create file ' + name)
else events.trigger('focus', [name]) else events.trigger('focus', [name])
...@@ -228,7 +232,7 @@ function fileExplorer (appAPI, files) { ...@@ -228,7 +232,7 @@ function fileExplorer (appAPI, files) {
if (label.innerText === '') { if (label.innerText === '') {
modalDialogCustom.alert('File name cannot be empty') modalDialogCustom.alert('File name cannot be empty')
label.innerText = textUnderEdit label.innerText = textUnderEdit
} else if (label.innerText.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) !== null) { } else if (files.checkSpecialChars(label.innerText)) {
modalDialogCustom.alert('Special characters are not allowed') modalDialogCustom.alert('Special characters are not allowed')
label.innerText = textUnderEdit label.innerText = textUnderEdit
} else if (!files.exists(newPath)) { } else if (!files.exists(newPath)) {
......
...@@ -45,6 +45,10 @@ class SharedFolder { ...@@ -45,6 +45,10 @@ class SharedFolder {
cb() cb()
} }
checkSpecialChars (name) {
return name.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) != null
}
init (cb) { init (cb) {
this.remixd.call('sharedfolder', 'list', {}, (error, filesList) => { this.remixd.call('sharedfolder', 'list', {}, (error, filesList) => {
if (error) { if (error) {
......
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