Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underscores in subdomains? #134

Closed
tasinet opened this issue Sep 19, 2021 · 5 comments
Closed

Underscores in subdomains? #134

tasinet opened this issue Sep 19, 2021 · 5 comments

Comments

@tasinet
Copy link

tasinet commented Sep 19, 2021

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
Copy link

Ditto, _dmarc.somedomain.com is a good example of that.

@jhnns
Copy link
Member

jhnns commented Jan 21, 2022

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
Copy link
Member

jhnns commented Jan 21, 2022

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
Copy link

i like the idea, STRICT being the default?

@jhnns jhnns closed this as completed in 171a8c8 Jan 23, 2022
@jhnns
Copy link
Member

jhnns commented Jan 23, 2022

Shipped with v5.0.0 🚀

import { parseDomain, Validation } from "parse-domain";

const parseResult = parseDomain("_jabber._tcp.gmail.com", {
  validation: Validation.Lax,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants