diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-25 10:01:33 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-25 10:01:33 +0100 |
commit | 0221f8c9b174c1c95b7348215f0d652bb1899c6b (patch) | |
tree | cbfbb6178aba96dabc84a065a227fcdfdd26fdac | |
parent | 56b0a516f24f2d527d84c0a26f14ef6807f055b2 (diff) | |
download | PeerTube-0221f8c9b174c1c95b7348215f0d652bb1899c6b.tar.gz PeerTube-0221f8c9b174c1c95b7348215f0d652bb1899c6b.tar.zst PeerTube-0221f8c9b174c1c95b7348215f0d652bb1899c6b.zip |
Trim video name also on server
-rw-r--r-- | client/src/app/shared/form-validators/video-validators.ts | 11 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 2 |
2 files changed, 7 insertions, 6 deletions
diff --git a/client/src/app/shared/form-validators/video-validators.ts b/client/src/app/shared/form-validators/video-validators.ts index 0000f18ba..1382a7747 100644 --- a/client/src/app/shared/form-validators/video-validators.ts +++ b/client/src/app/shared/form-validators/video-validators.ts | |||
@@ -3,15 +3,14 @@ import { BuildFormValidator } from './form-validator.model' | |||
3 | 3 | ||
4 | export const trimValidator: ValidatorFn = (control: FormControl) => { | 4 | export const trimValidator: ValidatorFn = (control: FormControl) => { |
5 | if (control.value.startsWith(' ') || control.value.endsWith(' ')) { | 5 | if (control.value.startsWith(' ') || control.value.endsWith(' ')) { |
6 | return { | 6 | return { spaces: true } |
7 | 'spaces': true | ||
8 | } | ||
9 | } | 7 | } |
10 | return null; | 8 | |
11 | }; | 9 | return null |
10 | } | ||
12 | 11 | ||
13 | export const VIDEO_NAME_VALIDATOR: BuildFormValidator = { | 12 | export const VIDEO_NAME_VALIDATOR: BuildFormValidator = { |
14 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120), trimValidator ], | 13 | VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ], |
15 | MESSAGES: { | 14 | MESSAGES: { |
16 | 'required': $localize`Video name is required.`, | 15 | 'required': $localize`Video name is required.`, |
17 | 'minlength': $localize`Video name must be at least 3 characters long.`, | 16 | 'minlength': $localize`Video name must be at least 3 characters long.`, |
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 26a671a1e..be05b2a69 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -62,6 +62,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([ | |||
62 | .custom((value, { req }) => isFileFieldValid(req.files, 'videofile')) | 62 | .custom((value, { req }) => isFileFieldValid(req.files, 'videofile')) |
63 | .withMessage('Should have a file'), | 63 | .withMessage('Should have a file'), |
64 | body('name') | 64 | body('name') |
65 | .trim() | ||
65 | .custom(isVideoNameValid) | 66 | .custom(isVideoNameValid) |
66 | .withMessage('Should have a valid name'), | 67 | .withMessage('Should have a valid name'), |
67 | body('channelId') | 68 | body('channelId') |
@@ -129,6 +130,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([ | |||
129 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 130 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
130 | body('name') | 131 | body('name') |
131 | .optional() | 132 | .optional() |
133 | .trim() | ||
132 | .custom(isVideoNameValid).withMessage('Should have a valid name'), | 134 | .custom(isVideoNameValid).withMessage('Should have a valid name'), |
133 | body('channelId') | 135 | body('channelId') |
134 | .optional() | 136 | .optional() |