Skip to content

Commit 03e61d0

Browse files
authored
refactor: allow uppercase in basic domain - regex (#994)
* refactor: allow uppercase in basic domain * refactor: allow uppercase in basic domain * refactor: allow uppercase in basic domain
1 parent 231064c commit 03e61d0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/regex/src/__tests__/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
phone,
3434
sixDigitsCode,
3535
spaces,
36+
uppercaseBasicDomain,
3637
url,
3738
} from '..'
3839

@@ -44,6 +45,8 @@ const asciiUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4445
const backupKeyTest = '123456789ABCEDFGHIJIKLMNOPQRSTUV'
4546
const domain = 'another-example.com'
4647
const subDomain = 'sub.another-example.com'
48+
const dashStartDomain = '-sub.another-example.com'
49+
const uppercaseDomain = 'SUB.another-example.com'
4750
const longTldDomain = 'sub.another-example.verylongtld'
4851
const cronTest = '0/15*-'
4952
const digitsTest = '0123456789'
@@ -461,6 +464,31 @@ describe('@regex', () => {
461464
expect(basicDomain.test(string)).toBe(expected)
462465
})
463466
})
467+
describe('uppercaseBasicDomain', () => {
468+
test.each([
469+
[asciiLetters, false],
470+
[asciiLowercase, false],
471+
[asciiUppercase, false],
472+
[backupKeyTest, false],
473+
[domain, true],
474+
[subDomain, true],
475+
[dashStartDomain, false],
476+
[uppercaseDomain, true],
477+
[longTldDomain, true],
478+
[digitsTest, false],
479+
[emailTest, false],
480+
[octdigits, false],
481+
[hexdigits, false],
482+
[printable, false],
483+
[punctuation, false],
484+
[whitespace, false],
485+
[cronTest, false],
486+
[macAddress1, false],
487+
...(urls.map(urlString => [urlString, false]) as [string, boolean][]),
488+
])('should match regex %s to be %s', (string, expected) => {
489+
expect(uppercaseBasicDomain.test(string)).toBe(expected)
490+
})
491+
})
464492

465493
describe('cron', () => {
466494
test.each([

packages/regex/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export const absoluteLinuxPath = /(^\/$|^(\/[a-zA-Z0-9_]+)*$)/
1919
export const ascii = /^[\x00-\x7F]+$/
2020
export const backupKey = /^[A-Z0-9]{32}$/
2121
export const basicDomain = /^[a-z0-9-]+(\.[a-z0-9-]{1,63})+$/
22+
export const uppercaseBasicDomain =
23+
/^(?![-])+[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,63})+$/
24+
2225
export const cron = /^[0-9,/*-]+$/
2326
export const digits = /^[0-9]*$/
2427
export const macAddress =

0 commit comments

Comments
 (0)