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

Implement "idn-hostname" format validator #412

Open
GuillaumeBlanchet opened this issue Apr 12, 2021 · 0 comments
Open

Implement "idn-hostname" format validator #412

GuillaumeBlanchet opened this issue Apr 12, 2021 · 0 comments

Comments

@GuillaumeBlanchet
Copy link

GuillaumeBlanchet commented Apr 12, 2021

idn-hostname is part of the json-schema specifications: https://json-schema.org/understanding-json-schema/reference/string.html#format

One could implement the feature like that:

public class IdnHostNameValidator implements FormatValidator {

  private static final IDNA idna = IDNA.getUTS46Instance(IDNA.NONTRANSITIONAL_TO_ASCII
      | IDNA.NONTRANSITIONAL_TO_UNICODE
      | IDNA.CHECK_BIDI
      | IDNA.CHECK_CONTEXTJ
      | IDNA.CHECK_CONTEXTO
      | IDNA.USE_STD3_RULES);

  @Override
  public Optional<String> validate(final String domain) {
    StringBuilder asciiDomain = new StringBuilder();
    IDNA.Info info = new IDNA.Info();
    idna.nameToASCII(domain, asciiDomain, info);
    if (info.hasErrors()) {
      return Optional.of(info.getErrors().toString());
    }
    return Optional.empty();
  }
}

parametrizing the icu library from unicode (https://mvnrepository.com/artifact/com.ibm.icu/icu4j) with domain constraints

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

1 participant