mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #322 from sharelatex/bg-validate-filename-length-client
validate filename length client
This commit is contained in:
commit
3c9eb07848
2 changed files with 34 additions and 3 deletions
|
@ -631,6 +631,9 @@ module.exports = ProjectEntityHandler =
|
||||||
newPath =
|
newPath =
|
||||||
fileSystem: "#{path.fileSystem}/#{element.name}"
|
fileSystem: "#{path.fileSystem}/#{element.name}"
|
||||||
mongo: path.mongo
|
mongo: path.mongo
|
||||||
|
# check if the path would be too long
|
||||||
|
if not SafePath.isAllowedLength newPath.fileSystem
|
||||||
|
return callback new Errors.InvalidNameError("path too long")
|
||||||
ProjectEntityHandler.checkValidElementName folder, element.name, (err) =>
|
ProjectEntityHandler.checkValidElementName folder, element.name, (err) =>
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
id = element._id+''
|
id = element._id+''
|
||||||
|
@ -648,9 +651,6 @@ module.exports = ProjectEntityHandler =
|
||||||
|
|
||||||
|
|
||||||
checkValidElementName: (folder, name, callback = (err) ->) ->
|
checkValidElementName: (folder, name, callback = (err) ->) ->
|
||||||
# # # check if the path would be too long
|
|
||||||
# # if not SafePath.isAllowedLength "#{folder}/#{name}"
|
|
||||||
# # return callback new Error.InvalidNameError("path too long")
|
|
||||||
# check if the name is already taken by a doc, file or
|
# check if the name is already taken by a doc, file or
|
||||||
# folder. If so, return an error "file already exists".
|
# folder. If so, return an error "file already exists".
|
||||||
err = new Errors.InvalidNameError("file already exists")
|
err = new Errors.InvalidNameError("file already exists")
|
||||||
|
|
|
@ -1399,6 +1399,37 @@ describe 'ProjectEntityHandler', ->
|
||||||
@ProjectModel.findOneAndUpdate.called.should.equal false
|
@ProjectModel.findOneAndUpdate.called.should.equal false
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should error if element name contains invalid characters", (done)->
|
||||||
|
doc =
|
||||||
|
_id: ObjectId()
|
||||||
|
name: "something*bad"
|
||||||
|
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
|
||||||
|
@ProjectModel.findOneAndUpdate.called.should.equal false
|
||||||
|
err.should.deep.equal new Errors.InvalidNameError("invalid element name")
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should error if element name is too long", (done)->
|
||||||
|
doc =
|
||||||
|
_id: ObjectId()
|
||||||
|
name: new Array(200).join("long-") + "something"
|
||||||
|
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
|
||||||
|
@ProjectModel.findOneAndUpdate.called.should.equal false
|
||||||
|
err.should.deep.equal new Errors.InvalidNameError("invalid element name")
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should error if the folder name is too long", (done)->
|
||||||
|
@path =
|
||||||
|
mongo: "mongo.path",
|
||||||
|
fileSystem: new Array(200).join("subdir/") + "foo"
|
||||||
|
@projectLocator.findElement.callsArgWith(1, null, @folder, @path)
|
||||||
|
doc =
|
||||||
|
_id: ObjectId()
|
||||||
|
name: "something"
|
||||||
|
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
|
||||||
|
@ProjectModel.findOneAndUpdate.called.should.equal false
|
||||||
|
err.should.deep.equal new Errors.InvalidNameError("path too long")
|
||||||
|
done()
|
||||||
|
|
||||||
it "should error if a document already exists with the same name", (done)->
|
it "should error if a document already exists with the same name", (done)->
|
||||||
doc =
|
doc =
|
||||||
_id: ObjectId()
|
_id: ObjectId()
|
||||||
|
|
Loading…
Reference in a new issue