Skip to content

URISyntaxException when trying to retrieve content #2208

@jpstotz

Description

@jpstotz

Describe the bug
When searching for files the returned GHContent does not correctly handle special characters in the URL, which causes an URISyntaxException and thus makes it impossible to retrieve the content.

To Reproduce

	public static void main(String[] args) throws Exception {
		GitHub github = new GitHubBuilder().withOAuthToken(TOKEN).build();

		// Build the search query
		String query = "filename:Package.swift repo:chrisgrieser/.config";

		// Execute search
		PagedSearchIterable<GHContent> results = github.searchContent().q(query).list();

		// Iterate results
		for (GHContent file : results) {
			System.out.println(file.getPath());
			System.out.println(file.getHtmlUrl());
			byte[] data = file.read().readAllBytes(); // GHException / URISyntaxException here
		}
	}
Exception in thread "main" org.kohsuke.github.GHException: Unable to build GitHub API URL
	at org.kohsuke.github.GitHubRequest.getApiURL(GitHubRequest.java:598)
	at org.kohsuke.github.GitHubRequest.<init>(GitHubRequest.java:664)
	at org.kohsuke.github.GitHubRequest$Builder.build(GitHubRequest.java:156)
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:690)
	at org.kohsuke.github.Requester.fetchInto(Requester.java:143)
	at org.kohsuke.github.GHContent.refresh(GHContent.java:300)
	at org.kohsuke.github.Refreshable.refresh(Refreshable.java:30)
	at org.kohsuke.github.GHContent.getEncodedContent(GHContent.java:145)
	at org.kohsuke.github.GHContent.readDecodedContent(GHContent.java:398)
	at org.kohsuke.github.GHContent.read(GHContent.java:287)
	at GitHubAPITest.main(GitHubAPITest.java:25)
Caused by: java.net.URISyntaxException: Illegal character in path at index 107: https://api.github.com/repositories/694641495/contents/Alfred.alfredpreferences/workflows/menubar-search%20[3rd-Party]/menu/Package.swift?ref=073e7b4493d088fdf1995a74cf5da201a5795181
	at java.base/java.net.URI$Parser.fail(URI.java:2976)
	at java.base/java.net.URI$Parser.checkChars(URI.java:3147)
	at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3229)
	at java.base/java.net.URI$Parser.parse(URI.java:3177)
	at java.base/java.net.URI.<init>(URI.java:623)
	at org.kohsuke.github.GitHubRequest.getApiURL(GitHubRequest.java:592)
	... 10 more

Additional context
Affected version: 2.0-rc.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions