Skip to content

Commit edb38e6

Browse files
committed
fixup! Remake website property saving with Vue
Signed-off-by: Christopher Ng <[email protected]>
1 parent 813bdf6 commit edb38e6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

apps/settings/src/constants/AccountPropertyConstants.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,11 @@ export const VERIFICATION_ENUM = Object.freeze({
202202
*/
203203
// eslint-disable-next-line no-control-regex
204204
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
205+
206+
/**
207+
* URL validation regex
208+
*
209+
* Sourced from https://github.com/hirak/phpjs/blob/ead6d1a542a0ce0b3969e2c1ea42e9213d12214d/functions/url/parse_url.js#L50*
210+
*/
211+
// eslint-disable-next-line no-control-regex
212+
export const VALIDATE_URL_REGEX = /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/

apps/settings/src/utils/validate.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* TODO add nice validation errors for Profile page settings modal
2727
*/
2828

29-
import { VALIDATE_EMAIL_REGEX } from '../constants/AccountPropertyConstants'
29+
import { VALIDATE_EMAIL_REGEX, VALIDATE_URL_REGEX } from '../constants/AccountPropertyConstants'
3030

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

49+
/**
50+
* Validate the URL input
51+
*
52+
* Compliant with PHP core FILTER_VALIDATE_URL validator*
53+
*
54+
* Reference implementation https://github.com/hirak/phpjs/blob/ead6d1a542a0ce0b3969e2c1ea42e9213d12214d/functions/url/parse_url.js#L50*
55+
*
56+
* @param {string} input the input
57+
* @return {boolean}
58+
*/
59+
export function validateUrl(input) {
60+
return typeof input === 'string'
61+
&& VALIDATE_URL_REGEX.test(input)
62+
}
63+
4964
/**
5065
* Validate the language input
5166
*

0 commit comments

Comments
 (0)