Skip to content

Access URIs that violate RFC 2396 #2646

@ChristianGruen

Description

@ChristianGruen

It is currently not possible to access the URI https://www.läuft-bei-dir.de/ via fn:doc and other functions, as Java’s HttpRequest.newBuilder method will reject the input.

As “invalid” URIs can be expected to occur more frequently in the future, we should think about workarounds. One way could be to manually convert the URI to its ASCII representation (should definitely be checked in more detail):

URI toASCII(String input) throws URISyntaxException {
  URI uri = new URI(input);
  String string = uri.getScheme() + "://";
  if(uri.getRawUserInfo() != null) string += uri.getRawUserInfo() + "@";
  String host = uri.getHost();
  if(host == null) {
    String auth = uri.getRawAuthority();
    String hp = auth.substring(auth.indexOf('@') + 1);
    int c = hp.lastIndexOf(':');
    host = c < 0 ? hp : hp.substring(0, c);
  }
  string += IDN.toASCII(host, IDN.ALLOW_UNASSIGNED);
  if(uri.getPort() != -1) string += ":" + uri.getPort();
  if(uri.getRawPath() != null) string += uri.getRawPath();
  if(uri.getRawQuery() != null) string += "?" + uri.getRawQuery();
  if(uri.getRawFragment() != null) string += "#" + uri.getRawFragment();
  return URI.create(new URI(string).toASCIIString());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions