libidn2: Guidance needed for avoiding STD3 rules

This is copy from: https://bugzilla.redhat.com/show_bug.cgi?id=1452750 (Florian Weimer writing)

For glibc, I want to permit _ in names, but I would like to use the default flags otherwise. I assumed that with libidn2 2.0.4, STD3 rules were disabled with flags 0, but this does not seem to be the case.

I run this program in a UTF-8 locale:

#include <err.h>
#include <idn2.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

void
print_1 (const char *name, const char *label, int flags)
{
  char *result;
  int ret = idn2_lookup_ul (name, &result, flags);
  if (ret == IDN2_OK)
    {
      printf("  %s: [[%s]]\n", label, result);
      free (result);
    }
  else
    printf ("  %s: %s\n", label, idn2_strerror_name (ret));
}

void
process (const char *name)
{
  printf ("[[%s]]:\n", name);
  print_1 (name, "default", 0);
  print_1 (name, "USE_STD3_ASCII_RULES", IDN2_USE_STD3_ASCII_RULES);
  print_1 (name, "TRANSITIONAL", IDN2_TRANSITIONAL);
  print_1 (name, "NONTRANSITIONAL", IDN2_NONTRANSITIONAL);
}

int
main (void)
{
  if (setlocale (LC_ALL, "") == NULL)
    err (1, "setlocale");
  process ("nämchen.example");
  process ("nämchen_foo.example");
  process ("nämchen$foo.example");
  process ("nämchen`foo.example");
  process ("nämchen;foo.example");
  process ("buße.example");
  return 0;
}

And I get (with libidn2-2.0.4-1.fc27.x86_64):

[[nämchen.example]]:
  default: [[xn--nmchen-bua.example]]
  USE_STD3_ASCII_RULES: [[xn--nmchen-bua.example]]
  TRANSITIONAL: [[xn--nmchen-bua.example]]
  NONTRANSITIONAL: [[xn--nmchen-bua.example]]
[[nämchen_foo.example]]:
  default: IDN2_DISALLOWED
  USE_STD3_ASCII_RULES: IDN2_DISALLOWED
  TRANSITIONAL: [[xn--nmchen_foo-q5a.example]]
  NONTRANSITIONAL: IDN2_DISALLOWED
[[nämchen$foo.example]]:
  default: IDN2_DISALLOWED
  USE_STD3_ASCII_RULES: IDN2_DISALLOWED
  TRANSITIONAL: [[xn--nmchen$foo-q5a.example]]
  NONTRANSITIONAL: IDN2_DISALLOWED
[[nämchen`foo.example]]:
  default: IDN2_DISALLOWED
  USE_STD3_ASCII_RULES: IDN2_DISALLOWED
  TRANSITIONAL: [[xn--nmchen`foo-q5a.example]]
  NONTRANSITIONAL: IDN2_DISALLOWED
[[nämchen;foo.example]]:
  default: IDN2_DISALLOWED
  USE_STD3_ASCII_RULES: IDN2_DISALLOWED
  TRANSITIONAL: [[xn--nmchen;foo-q5a.example]]
  NONTRANSITIONAL: IDN2_DISALLOWED
[[buße.example]]:
  default: [[xn--bue-6ka.example]]
  USE_STD3_ASCII_RULES: [[xn--bue-6ka.example]]
  TRANSITIONAL: [[busse.example]]
  NONTRANSITIONAL: [[xn--bue-6ka.example]]

I don't want to use IDN2_TRANSITIONAL because it gives the wrong IDNA name for buße.example, so it seems to me that there aren't any good options at present.

Edited by Nikos Mavrogiannopoulos