mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-11 03:27:19 +00:00
use extended file validation rules in frontend
This commit is contained in:
parent
ddf1d6e65e
commit
76281a3d79
1 changed files with 27 additions and 3 deletions
|
@ -1,12 +1,36 @@
|
|||
define [
|
||||
"base"
|
||||
], (App) ->
|
||||
|
||||
# copied from app/coffee/Features/Project/SafePath.coffee
|
||||
|
||||
BADCHAR_RX = ///
|
||||
[
|
||||
\/ # no slashes
|
||||
\* # no asterisk
|
||||
\u0000-\u001F # no control characters (0-31)
|
||||
\u007F # no delete
|
||||
\u0080-\u009F # no unicode control characters (C1)
|
||||
\uD800-\uDFFF # no unicode surrogate characters
|
||||
]
|
||||
///g
|
||||
|
||||
BADFILE_RX = ///
|
||||
(^\.$) # reject . as a filename
|
||||
| (^\.\.$) # reject .. as a filename
|
||||
| (^\s+) # reject leading space
|
||||
| (\s+$) # reject trailing space
|
||||
///g
|
||||
|
||||
MAX_PATH = 1024 # Maximum path length, in characters. This is fairly arbitrary.
|
||||
|
||||
App.directive "validFile", () ->
|
||||
return {
|
||||
require: 'ngModel'
|
||||
link: (scope, element, attrs, ngModelCtrl) ->
|
||||
ngModelCtrl.$validators.validFile = (modelValue) ->
|
||||
validFileRegex = /^[^\*\/]*$/ # Don't allow * and /
|
||||
isValid = modelValue.match validFileRegex
|
||||
ngModelCtrl.$validators.validFile = (filename) ->
|
||||
isValid = filename.length > 0 && filename.length < MAX_PATH &&
|
||||
not filename.match(BADCHAR_RX) &&
|
||||
not filename.match(BADFILE_RX)
|
||||
return isValid
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue