ReviewOS

also looking at this

stacks/ts-dns

fix: allow underscores in domain labels

#2057
Open lu-zero wants to merge fix/allow-underscores-in-domain-labels into main
2 files +19 -2
src/client.tsmodified+2-2
Changes to src/client.ts
@@ -41,7 +41,7 @@ export class DnsClient {
4141 * - Start/end dots
4242 * - Overall length (max 253 characters)
4343 * - Label length (max 63 characters)
44 * - Valid characters (a-z, 0-9, -)
44 * - Valid characters (a-z, 0-9, -, _)
4545 *
4646 * @param domain - The domain name to validate
4747 * @throws {Error} If the domain name is invalid
@@ -70,7 +70,7 @@ export class DnsClient {
7070 }
7171
7272 // Check label characters
73 if (!/^[a-z0-9-]+$/i.test(label)) {
73 if (!/^[a-z0-9_-]+$/i.test(label)) {
7474 throw new Error(`Invalid characters in domain label: ${label}`)
7575 }
7676 }
test/dnsx.test.tsmodified+17-0
Changes to test/dnsx.test.ts
@@ -187,6 +187,23 @@ describe('DnsClient', () => {
187187 })).toThrow()
188188 })
189189
190 it('should accept underscores in domain labels (DKIM, DMARC, SRV)', () => {
191 expect(() => new DnsClient({
192 domains: ['selector1._domainkey.example.com'],
193 type: 'TXT',
194 })).not.toThrow()
195
196 expect(() => new DnsClient({
197 domains: ['_dmarc.example.com'],
198 type: 'TXT',
199 })).not.toThrow()
200
201 expect(() => new DnsClient({
202 domains: ['_sip._tcp.example.com'],
203 type: 'SRV',
204 })).not.toThrow()
205 })
206
190207 it('should handle invalid record types', () => {
191208 expect(() => new DnsClient({
192209 domains: ['example.com'],