Skip to content

Commit

Permalink
fixup! Remake website property saving with Vue
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Jul 26, 2022
1 parent ac555cc commit 3001b77
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions apps/settings/src/constants/AccountPropertyConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,11 @@ export const VERIFICATION_ENUM = Object.freeze({
*/
// eslint-disable-next-line no-control-regex
export const VALIDATE_EMAIL_REGEX = /^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/i

/**
* URL validation regex
*
* Sourced from https://github.com/hirak/phpjs/blob/ead6d1a542a0ce0b3969e2c1ea42e9213d12214d/functions/url/parse_url.js#L50*
*/
// eslint-disable-next-line no-control-regex
export const VALIDATE_URL_REGEX = /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/
17 changes: 16 additions & 1 deletion apps/settings/src/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* TODO add nice validation errors for Profile page settings modal
*/

import { VALIDATE_EMAIL_REGEX } from '../constants/AccountPropertyConstants'
import { VALIDATE_EMAIL_REGEX, VALIDATE_URL_REGEX } from '../constants/AccountPropertyConstants'

/**
* Validate the email input
Expand All @@ -46,6 +46,21 @@ export function validateEmail(input) {
&& encodeURIComponent(input).replace(/%../g, 'x').length <= 320
}

/**
* Validate the URL input
*
* Compliant with PHP core FILTER_VALIDATE_URL validator*
*
* Reference implementation https://github.com/hirak/phpjs/blob/ead6d1a542a0ce0b3969e2c1ea42e9213d12214d/functions/url/parse_url.js#L50*
*
* @param {string} input the input
* @return {boolean}
*/
export function validateUrl(input) {
return typeof input === 'string'
&& VALIDATE_URL_REGEX.test(input)
}

/**
* Validate the language input
*
Expand Down

0 comments on commit 3001b77

Please sign in to comment.