docs: private static String correct(String url) {
      // Fix for bad URLs containing UNC paths
      // If the url is a UNC file url it must be specified like:
      // file:////<PATH>...
      if (url.startsWith("file://")
      // A url like file:///<PATH> refers to a local file so it must not be
      // modified.
          && !url.startsWith("file:///") && isWindows()) {
        url = "file:////" + url.substring("file://".length());
      }
  
      String userInfo = getUserInfo(url);
      String user = extractUser(userInfo);
      String pass = extractPassword(userInfo);
  
      String initialUrl = url;
      // See if the url contains user and password. If so we remove them and
      // attach them back after the correction is performed.
      if (user != null || pass != null) {
        URL urlWithoutUserInfo = clearUserInfo(url);
        if (urlWithoutUserInfo != null) {
          url = clearUserInfo(url).toString();
        } else {
          // Possible a malformed URL
        }
      }
  
      // If there is a % that means the url was already corrected.
      if (url.contains("%")) {
        return initialUrl;
      }
  
      // Extract the reference (anchor) part from the url. The '#' char
      // identifying the anchor must not be corrected.
      String reference = null;
      int refIndex = url.lastIndexOf('#');
      if (refIndex != -1) {
        reference = filepath2URI(url.substring(refIndex + 1));
        url = url.substring(0, refIndex);
      }
  
      // Buffer where eventual query string will be processed.
      StringBuilder queryBuffer = null;
  
      int queryIndex = url.indexOf('?');
      if (queryIndex != -1) {
        // We have a query
        String query = url.substring(queryIndex + 1);
        url = url.substring(0, queryIndex);
        queryBuffer = new StringBuilder(query.length());
        // Tokenize by &
        StringTokenizer st = new StringTokenizer(query, "&");
        while (st.hasMoreElements()) {
          String token = st.nextToken();
          token = filepath2URI(token);
          // Correct token
          queryBuffer.append(token);
          if (st.hasMoreElements()) {
            queryBuffer.append("&");
          }
        }
      }
  
      String toReturn = filepath2URI(url);
  
      if (queryBuffer != null) {
        // Append to the end the corrected query.
        toReturn += "?" + queryBuffer.toString();
      }
  
      if (reference != null) {
        // Append the reference to the end the corrected query.
        toReturn += "#" + reference;
      }
  
      // Re-attach the user and password.
      if (user != null || pass != null) {
        try {
          if (user == null) {
            user = "";
          }
          if (pass == null) {
            pass = "";
          }
          // Re-attach user info.
          toReturn = attachUserInfo(new URL(toReturn), user, pass.toCharArray())
              .toString();
        } catch (MalformedURLException e) {
          // Shoudn't happen.
        }
      }
      return toReturn;
    }