-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add backend url validation (#4009)
* fix: add backend url validation * test: update links to be valid * fix: add url validation for building selection criteria * test: update buildingSelectionCriteria to be valid url
- Loading branch information
1 parent
e7cf68d
commit d926e8f
Showing
9 changed files
with
84 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
registerDecorator, | ||
ValidationArguments, | ||
ValidationOptions, | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
} from 'class-validator'; | ||
|
||
export function hasHttps(validationOptions?: ValidationOptions) { | ||
return function (object: unknown, propertyName: string) { | ||
registerDecorator({ | ||
target: object.constructor, | ||
propertyName, | ||
options: validationOptions, | ||
constraints: [], | ||
validator: hasHttpsConstraint, | ||
}); | ||
}; | ||
} | ||
|
||
@ValidatorConstraint({ name: 'hasHttps' }) | ||
export class hasHttpsConstraint implements ValidatorConstraintInterface { | ||
validate(url: string) { | ||
const httpsRegex = /^https?:\/\//i; | ||
return httpsRegex.test(url); | ||
} | ||
|
||
defaultMessage(args: ValidationArguments) { | ||
return `${args.property} must have https://`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters