0
Fork 0
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:
Charles Zhao 2024-01-26 12:55:56 +08:00 committed by GitHub
parent c2e6a610bc
commit f2e978d2d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View 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);
});
});

View file

@ -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,}$/;