Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit 225ccaa

Browse files
authored
Merge pull request #61 from uptick/fix/no-backslashes-allowed
UP-1895 Documents - no more backslash havoc
2 parents 51a3aa8 + 4d4c8ec commit 225ccaa

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

demo-site/nested-editable.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,34 +54,28 @@ class NestedEditableDemo extends React.Component {
5454
})
5555
}
5656
handleCreateFiles = (files, prefix) => {
57-
this.setState(state => {
57+
this.setState(prevState => {
5858
const newFiles = files.map((file) => {
5959
let newKey = prefix
6060
if (prefix !== '' && prefix.substring(prefix.length - 1, prefix.length) !== '/') {
6161
newKey += '/'
6262
}
63+
const invalidChar = ['/', '\\']
64+
if (invalidChar.some(char => file.name.indexOf(char) !== -1)) return
6365
newKey += file.name
6466
return {
6567
key: newKey,
6668
size: file.size,
6769
modified: +Moment(),
6870
}
6971
})
70-
7172
const uniqueNewFiles = []
72-
newFiles.map((newFile) => {
73-
let exists = false
74-
state.files.map((existingFile) => {
75-
if (existingFile.key === newFile.key) {
76-
exists = true
77-
}
78-
})
79-
if (!exists) {
80-
uniqueNewFiles.push(newFile)
81-
}
73+
newFiles.forEach((newFile) => {
74+
const exists = prevState.files.some(existingFile => (existingFile.key === newFile.key))
75+
if (!exists) uniqueNewFiles.push(newFile)
8276
})
83-
state.files = state.files.concat(uniqueNewFiles)
84-
return state
77+
const updatedFiles = [...prevState.files, uniqueNewFiles]
78+
return { files: updatedFiles }
8579
})
8680
}
8781
handleRenameFolder = (oldKey, newKey) => {

src/base-file.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class BaseFile extends React.Component {
6565

6666
handleFileClick = (event) => {
6767
event && event.preventDefault()
68-
6968
this.props.browserProps.preview({
7069
url: this.props.url,
7170
name: this.getName(),
@@ -109,15 +108,14 @@ class BaseFile extends React.Component {
109108
// })
110109
return
111110
}
112-
if (newName.indexOf('/') !== -1) {
113-
// todo: move to props handler
114-
// window.notify({
115-
// style: 'error',
116-
// title: 'Invalid new file name',
117-
// body: 'File names cannot contain forward slashes.',
118-
// })
119-
return
120-
}
111+
const invalidChar = ['/', '\\']
112+
if (invalidChar.some(char => newName.indexOf(char) !== -1)) return
113+
// todo: move to props handler
114+
// window.notify({
115+
// style: 'error',
116+
// title: 'Invalid new file name',
117+
// body: 'File names cannot contain forward slashes.',
118+
// })
121119
let newKey = newName
122120
const slashIndex = this.props.fileKey.lastIndexOf('/')
123121
if (slashIndex !== -1) {

src/base-folder.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BaseFolder extends React.Component {
8080
}
8181
handleNewNameChange = (event) => {
8282
const newName = this.newNameRef.value
83-
this.setState({newName: newName})
83+
this.setState({ newName: newName })
8484
}
8585
handleRenameSubmit = (event) => {
8686
event.preventDefault()
@@ -97,15 +97,15 @@ class BaseFolder extends React.Component {
9797
// })
9898
return
9999
}
100-
if (newName.indexOf('/') !== -1) {
101-
// todo: move to props handler
102-
// window.notify({
103-
// style: 'error',
104-
// title: 'Invalid new folder name',
105-
// body: 'Folder names cannot contain forward slashes.',
106-
// })
107-
return
108-
}
100+
const invalidChar = ['/', '\\']
101+
if (invalidChar.some(char => newName.indexOf(char) !== -1)) return
102+
// todo: move to props handler
103+
// window.notify({
104+
// style: 'error',
105+
// title: 'Invalid new folder name',
106+
// body: 'Folder names cannot contain forward slashes.',
107+
// })
108+
109109
let newKey = this.props.fileKey.substr(0, this.props.fileKey.substr(0, this.props.fileKey.length - 1).lastIndexOf('/'))
110110
if (newKey.length) {
111111
newKey += '/'

0 commit comments

Comments
 (0)