Merge pull request #320 from sharelatex/ja-validate-filenames

Don't allow files to be created with / or * characters
This commit is contained in:
James Allen 2016-09-23 09:42:48 +01:00 committed by GitHub
commit 2b317cab6c
4 changed files with 41 additions and 3 deletions

View file

@ -315,8 +315,12 @@ script(type='text/ng-template', id='newDocModalTemplate')
required, required,
ng-model="inputs.name", ng-model="inputs.name",
on-enter="create()", 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 .modal-footer
button.btn.btn-default( button.btn.btn-default(
ng-disabled="state.inflight" ng-disabled="state.inflight"
@ -341,8 +345,12 @@ script(type='text/ng-template', id='newFolderModalTemplate')
required, required,
ng-model="inputs.name", ng-model="inputs.name",
on-enter="create()", 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 .modal-footer
button.btn.btn-default( button.btn.btn-default(
ng-disabled="state.inflight" ng-disabled="state.inflight"
@ -414,3 +422,13 @@ script(type='text/ng-template', id='deleteEntityModalTemplate')
) )
span(ng-hide="state.inflight") #{translate("delete")} span(ng-hide="state.inflight") #{translate("delete")}
span(ng-show="state.inflight") #{translate("deleting")}... 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')}

View file

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

View file

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

View file

@ -26,9 +26,23 @@ define [
$scope.startRenaming = () -> $scope.startRenaming = () ->
$scope.entity.renaming = true $scope.entity.renaming = true
invalidModalShowing = false
$scope.finishRenaming = () -> $scope.finishRenaming = () ->
delete $scope.entity.renaming
name = $scope.inputs.name name = $scope.inputs.name
if !name.match(new RegExp(ide.validFileRegex))
# 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 if !name? or name.length == 0
$scope.inputs.name = $scope.entity.name $scope.inputs.name = $scope.entity.name
return return