Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/regex/src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ const printable =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
const punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
const sixDigitsCodeTest = '123456'
const url1 = 'http://console.scaleway.com'
const url2 = 'https://www.scaleway.com'
const urls = [
'http://console.scaleway.com',
'https://www.scaleway.com',
'https://www.scaleway.online',
'http://www.scaleway.com:8080',
'http://255.255.255.255',
'http://www.example.com/product',
'http://www.example.com/products?id=1&page=2',
'http://www.example.com#up',
]
const whitespace = ' \t\n\r\x0b\x0c'
const macAddress1 = '1F:B5:FA:47:CD:C4'
const linuxPaths = {
Expand Down Expand Up @@ -420,8 +428,7 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
[url1, false],
[url2, false],
...(urls.map(urlString => [urlString, false]) as [string, boolean][]),
])('should match regex %s to be %s', (string, expected) => {
expect(basicDomain.test(string)).toBe(expected)
})
Expand Down Expand Up @@ -604,8 +611,9 @@ describe('@regex', () => {
[whitespace, false],
[cronTest, false],
[macAddress1, false],
[url1, true],
[url2, true],
[domain, false],
[subDomain, false],
...(urls.map(urlString => [urlString, true]) as [string, boolean][]),
])('should match regex %s to be %s', (string, expected) => {
expect(url.test(string)).toBe(expected)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/regex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export const phone = /^\+[0-9]*/
export const spaces = /^\s*$/
export const sixDigitsCode = /^[0-9]{6}$/
export const url =
/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
/^http(s)?:\/\/?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/
export const hexadecimal = /^[0-9a-fA-F]+$/