rsuite / schema-typed

Schema for data modeling & validation
MIT License
198 stars 28 forks source link

RegEx for URL doesn't match `mailto:` URL #45

Closed t83714 closed 1 year ago

t83714 commented 2 years ago

What version of schema-typed are you using?

5.13.0

Describe the Bug

The regex expression used by the isURL method doesn't match mailto URL e.g. mailto:someone@yoursite.com

https://github.com/rsuite/schema-typed/blob/893a1654514d854dfd321158f9c650c221f31871/src/StringType.ts#L80

Expected Behavior

The above regex should match string mailto:someone@yoursite.com

To Reproduce

Test the above regex at https://www.regextester.com/

RokeJulianLockhart commented 1 year ago

@t83714, I was provided similar RegEx by https://stackoverflow.com/questions/25703360/regular-expression-extract-subdomain-domain#comment40178155_25703800

^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$

any idea of the origin of it?

SevenOutman commented 1 year ago

According to RFC 2368, a mailto link is also a type of URL, thus isURL rule should be able to match mailto links, or at least provide an option to enable it.