Procházet zdrojové kódy

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

fix backslash on v1 and template import

GitOrigin-RevId: 8410a80a06ef48610f7b18f4556bd073253d4eb7
Brian Gough před 7 roky
rodič
revize
2ea0644cfa

+ 6 - 1
services/web/app/coffee/Features/Project/ProjectDetailsHandler.coffee

@@ -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

+ 9 - 1
services/web/test/unit/coffee/Project/ProjectDetailsHandlerTests.coffee

@@ -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)