mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
fix(toolkit): domain regex should allow short subdomain and top-level domain (#5319)
This commit is contained in:
parent
c2e6a610bc
commit
f2e978d2d9
2 changed files with 19 additions and 2 deletions
18
packages/toolkit/core-kit/src/regex.test.ts
Normal file
18
packages/toolkit/core-kit/src/regex.test.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { domainRegEx } from './regex.js';
|
||||
|
||||
describe('Regular expressions should work as expected', () => {
|
||||
it('should allow valid domains that consists of 3 parts. E.g. foo.bar.com', () => {
|
||||
expect(domainRegEx.test('foo.bar.com')).toBe(true);
|
||||
expect(domainRegEx.test('foo1.bar.com')).toBe(true);
|
||||
expect(domainRegEx.test('foo.bar1.com')).toBe(true);
|
||||
expect(domainRegEx.test('1foo.bar.com')).toBe(true);
|
||||
expect(domainRegEx.test('f.bar.co')).toBe(true);
|
||||
expect(domainRegEx.test('f.b.com')).toBe(true);
|
||||
expect(domainRegEx.test('1.b.tk')).toBe(true);
|
||||
});
|
||||
|
||||
it('should not allow domains that consists of 2 parts. E.g. bar.com', () => {
|
||||
expect(domainRegEx.test('bar.com')).toBe(false);
|
||||
expect(domainRegEx.test('b.co')).toBe(false);
|
||||
});
|
||||
});
|
|
@ -8,5 +8,4 @@ export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
|
|||
export const dateRegex = /^\d{4}(-\d{2}){2}/;
|
||||
export const noSpaceRegEx = /^\S+$/;
|
||||
/** Full domain that consists of at least 3 parts, e.g. foo.bar.com */
|
||||
export const domainRegEx =
|
||||
/^[\dA-Za-z][\dA-Za-z-]*[\dA-Za-z](\.[\dA-Za-z][\dA-Za-z-]*[\dA-Za-z]){2,}$/;
|
||||
export const domainRegEx = /^[\dA-Za-z]+(\.[\dA-Za-z]+){2,}$/;
|
||||
|
|
Loading…
Add table
Reference in a new issue