0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(toolkit): support dash in domain (#5413)

This commit is contained in:
wangsijie 2024-02-20 13:00:53 +08:00 committed by GitHub
parent b6233a1a58
commit a78acef579
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -15,4 +15,11 @@ describe('Regular expressions should work as expected', () => {
expect(domainRegEx.test('bar.com')).toBe(false); expect(domainRegEx.test('bar.com')).toBe(false);
expect(domainRegEx.test('b.co')).toBe(false); expect(domainRegEx.test('b.co')).toBe(false);
}); });
it('should handle domains that contains dash in the middle. E.g. auth-gate.bar.com', () => {
expect(domainRegEx.test('auth-gate.bar.com')).toBe(true);
expect(domainRegEx.test('auth-.bar.com')).toBe(false);
expect(domainRegEx.test('-auth.bar.com')).toBe(false);
expect(domainRegEx.test('auth.bar-foo.com')).toBe(true);
});
}); });

View file

@ -7,5 +7,6 @@ export const mobileUriSchemeProtocolRegEx = /^[a-z][\d+_a-z-]*(\.[\d+_a-z-]+)+:$
export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i; export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
export const dateRegex = /^\d{4}(-\d{2}){2}/; export const dateRegex = /^\d{4}(-\d{2}){2}/;
export const noSpaceRegEx = /^\S+$/; export const noSpaceRegEx = /^\S+$/;
/** Full domain that consists of at least 3 parts, e.g. foo.bar.com */ /** Full domain that consists of at least 3 parts, e.g. foo.bar.com or example-foo.bar.com */
export const domainRegEx = /^[\dA-Za-z]+(\.[\dA-Za-z]+){2,}$/; export const domainRegEx =
/^[\dA-Za-z](?:[\dA-Za-z-]*[\dA-Za-z])?(?:\.[\dA-Za-z](?:[\dA-Za-z-]*[\dA-Za-z])?){2,}$/;