Underscores in subdomains?
tasinet opened this issue ยท 5 comments
tasinet commented
Are you interested in supporting underscores in subdomains? They are quite legal and somewhat common, and this lib (like many) throws an unsupported character error in such cases.
I have a rough fix in my fork, I can PR if you want.
randalpinto commented
Ditto, _dmarc.somedomain.com
is a good example of that.
jhnns commented
Sure ๐
While doing a quick research, I just stumbled upon https://stackoverflow.com/a/2183140
Maybe we shouldn't validate the characters after all... what do you think?
Anyway, you can send my a PR adding _
as allowed character for now
jhnns commented
I changed my mind. I'm going to allow 2 different validation modes:
export enum Validation {
/**
* Allows any octets as labels
* but still restricts the length of labels and the overall domain.
*
* @see https://www.rfc-editor.org/rfc/rfc2181#section-11
**/
Lax = "LAX",
/**
* Only allows ASCII letters, digits and hyphens (aka LDH),
* forbids hyphens at the the beginning or end of a label
* and requires top-level domain names not to be all-numeric.
*
* This is the default if no validation is configured.
*
* @see https://datatracker.ietf.org/doc/html/rfc3696#section-2
*/
Strict = "STRICT",
}
What do you think?
randalpinto commented
i like the idea, STRICT being the default?
jhnns commented
Shipped with v5.0.0 ๐
import { parseDomain, Validation } from "parse-domain";
const parseResult = parseDomain("_jabber._tcp.gmail.com", {
validation: Validation.Lax,
});