mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
fix filename length check
This commit is contained in:
parent
14ef9a2c49
commit
2c2b6e5f36
2 changed files with 25 additions and 3 deletions
|
@ -631,6 +631,9 @@ module.exports = ProjectEntityHandler =
|
|||
newPath =
|
||||
fileSystem: "#{path.fileSystem}/#{element.name}"
|
||||
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) =>
|
||||
return callback(err) if err?
|
||||
id = element._id+''
|
||||
|
@ -648,9 +651,6 @@ module.exports = ProjectEntityHandler =
|
|||
|
||||
|
||||
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
|
||||
# folder. If so, return an error "file already exists".
|
||||
err = new Errors.InvalidNameError("file already exists")
|
||||
|
|
|
@ -1399,6 +1399,28 @@ describe 'ProjectEntityHandler', ->
|
|||
@ProjectModel.findOneAndUpdate.called.should.equal false
|
||||
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)->
|
||||
doc =
|
||||
_id: ObjectId()
|
||||
|
|
Loading…
Reference in a new issue