Skip to content

Commit

Permalink
Fix domain validation function ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
wotschofsky committed Dec 15, 2024
1 parent a8184a4 commit 78ee327
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('isValidDomain', () => {
'theofficialabsolutelongestdomainnameregisteredontheworldwideweb.international',
),
).toBe(true);
expect(isValidDomain('_dmarc.example.com')).toBe(true);
});

it('validates wildcard domains', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const isValidDomain = (domain: string) => {
if (domain.length > 253 || domain.length === 0) return false;

// Remove wildcard prefix or leading underscore, trailing dot (if fully qualified domain name)
const cleanedDomain = domain.replace(/^(\*\.)|_/, '').replace(/\.$/, '');
const cleanedDomain = domain.replace(/^(\*\.|_)/, '').replace(/\.$/, '');

// Split domain into labels
const labels = cleanedDomain.split('.');
Expand Down

0 comments on commit 78ee327

Please sign in to comment.