Merge pull request #1082 from sharelatex/bg-fix-backslash-on-v1-and-template-import

fix backslash on v1 and template import

GitOrigin-RevId: 8410a80a06ef48610f7b18f4556bd073253d4eb7
This commit is contained in:
Brian Gough 2018-11-06 08:20:19 +00:00 committed by sharelatex
parent 4733a7940d
commit 2ea0644cfa
2 changed files with 15 additions and 2 deletions

View file

@ -63,7 +63,9 @@ module.exports = ProjectDetailsHandler =
else if name.length > @MAX_PROJECT_NAME_LENGTH
return callback(new Errors.InvalidNameError("Project name is too long"))
else if name.indexOf("/") > -1
return callback(new Errors.InvalidNameError("Project name cannot not contain / characters"))
return callback(new Errors.InvalidNameError("Project name cannot contain / characters"))
else if name.indexOf("\\") > -1
return callback(new Errors.InvalidNameError("Project name cannot contain \\ characters"))
else
return callback()
@ -112,6 +114,9 @@ module.exports = ProjectDetailsHandler =
if name.indexOf('/') > -1
# v2 does not allow / in a project name
name = name.replace(/\//g, '-')
if name.indexOf('\\') > -1
# backslashes in project name will prevent syncing to dropbox
name = name.replace(/\\/g, '')
if name.length > @MAX_PROJECT_NAME_LENGTH
name = name.substr(0, @MAX_PROJECT_NAME_LENGTH)
return name

View file

@ -140,11 +140,16 @@ describe 'ProjectDetailsHandler', ->
expect(error).to.exist
done()
it "should reject empty names with /s", (done) ->
it "should reject names with /s", (done) ->
@handler.validateProjectName "foo/bar", (error) ->
expect(error).to.exist
done()
it "should reject names with \\s", (done) ->
@handler.validateProjectName "foo\\bar", (error) ->
expect(error).to.exist
done()
it "should reject long names", (done) ->
@handler.validateProjectName new Array(1000).join("a"), (error) ->
expect(error).to.exist
@ -204,6 +209,9 @@ describe 'ProjectDetailsHandler', ->
it "should replace / with -", () ->
expect(@handler.fixProjectName "foo/bar").to.equal "foo-bar"
it "should replace \\ with ''", () ->
expect(@handler.fixProjectName "foo \\ bar").to.equal "foo bar"
it "should truncate long names", () ->
expect(@handler.fixProjectName new Array(1000).join("a")).to.equal "a".repeat(150)