Przeglądaj źródła

Don't allow files to be created with / or * characters

Requires the following translations:

  "files_cannot_include_invalid_characters": "Files cannot include '*' or '/' characters",
  "invalid_file_name": "Invalid File Name"
James Allen 10 lat temu
rodzic
commit
4386ab1225

+ 20 - 2
services/web/app/views/project/editor/file-tree.jade

@@ -315,8 +315,12 @@ script(type='text/ng-template', id='newDocModalTemplate')
 				required,
 				ng-model="inputs.name",
 				on-enter="create()",
-				select-name-on="open"
+				select-name-on="open",
+				ng-pattern="validFileRegex",
+				name="name"
 			)
+			.text-danger.row-spaced-small(ng-show="newDocForm.name.$error.pattern")
+				| #{translate('files_cannot_include_invalid_characters')}
 	.modal-footer
 		button.btn.btn-default(
 			ng-disabled="state.inflight"
@@ -341,8 +345,12 @@ script(type='text/ng-template', id='newFolderModalTemplate')
 				required,
 				ng-model="inputs.name",
 				on-enter="create()",
-				select-name-on="open"
+				select-name-on="open",
+				ng-pattern="validFileRegex",
+				name="name"
 			)
+			.text-danger.row-spaced-small(ng-show="newFolderForm.name.$error.pattern")
+				| #{translate('files_cannot_include_invalid_characters')}
 	.modal-footer
 		button.btn.btn-default(
 			ng-disabled="state.inflight"
@@ -414,3 +422,13 @@ script(type='text/ng-template', id='deleteEntityModalTemplate')
 		)
 			span(ng-hide="state.inflight") #{translate("delete")}
 			span(ng-show="state.inflight") #{translate("deleting")}...
+
+script(type='text/ng-template', id='invalidFileNameModalTemplate')
+	.modal-header
+		h3 #{translate('invalid_file_name')}
+	.modal-body
+		p #{translate('files_cannot_include_invalid_characters')}
+	.modal-footer
+		button.btn.btn-default(
+			ng-click="$close()"
+		) #{translate('ok')}

+ 2 - 0
services/web/public/coffee/ide.coffee

@@ -87,6 +87,8 @@ define [
 		# End of tracking code.
 
 		window._ide = ide
+		
+		ide.validFileRegex = '^[^\*\/]*$' # Don't allow * and /
 
 		ide.project_id = $scope.project_id = window.project_id
 		ide.$scope = $scope

+ 4 - 0
services/web/public/coffee/ide/file-tree/controllers/FileTreeController.coffee

@@ -44,6 +44,8 @@ define [
 	App.controller "NewDocModalController", [
 		"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
 		($scope,   ide,   $modalInstance,   $timeout,   parent_folder) ->
+			$scope.validFileRegex = ide.validFileRegex
+			
 			$scope.inputs = 
 				name: "name.tex"
 			$scope.state =
@@ -74,6 +76,8 @@ define [
 	App.controller "NewFolderModalController", [
 		"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
 		($scope,   ide,   $modalInstance,   $timeout,   parent_folder) ->
+			$scope.validFileRegex = ide.validFileRegex
+
 			$scope.inputs = 
 				name: "name"
 			$scope.state =

+ 15 - 1
services/web/public/coffee/ide/file-tree/controllers/FileTreeEntityController.coffee

@@ -26,9 +26,23 @@ define [
 		$scope.startRenaming = () ->
 			$scope.entity.renaming = true
 
+		invalidModalShowing = false
 		$scope.finishRenaming = () ->
-			delete $scope.entity.renaming
 			name = $scope.inputs.name
+			
+			if !name.match(/^[^\*\/]*$/)
+				# Showing the modal blurs the rename box which calls us again
+				# so track this with the invalidModalShowing flag
+				return if invalidModalShowing
+				invalidModalShowing = true
+				modal = $modal.open(
+					templateUrl: "invalidFileNameModalTemplate"
+				)
+				modal.result.then () ->
+					invalidModalShowing = false
+				return
+				
+			delete $scope.entity.renaming
 			if !name? or name.length == 0
 				$scope.inputs.name = $scope.entity.name
 				return