private URI fixInvalidGithubUrl()

in src/main/java/com/spotify/github/v3/repos/BranchProtectionUrlDeserializer.java [36:48]


  private URI fixInvalidGithubUrl(final String invalidUrl) {
    // There's a bug in github where it gives you back non-url-encoded characters
    // in the protection_url field. For example if your branch has a single "%" in its name.
    // As of this writing, the protection URL looks something like this
    // https://github-server.tld/api/v3/repos/owner/repo-name/branches/branch-name/protection
    final String[] schemaAndPath = invalidUrl.split("//");
    String[] pathParts = schemaAndPath[1].split("/");
    for (int i = 0; i < pathParts.length; i++) {
      pathParts[i] = URLEncoder.encode(pathParts[i], StandardCharsets.UTF_8);
    }
    String fixedUrlString = schemaAndPath[0] + "//" + String.join("/", pathParts);
    return URI.create(fixedUrlString);
  }