Skip to content

Commit 33efc17

Browse files
committed
Use URLs as-is to prevent double percent-encoding
Closes gh-46
1 parent 5f513ec commit 33efc17

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

Diff for: src/main/java/io/spring/issuebot/github/GitHubTemplate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private <T> Page<T> getPage(String url, Class<T[]> type) {
139139
if (!StringUtils.hasText(url)) {
140140
return null;
141141
}
142-
ResponseEntity<T[]> contents = this.rest.getForEntity(url, type);
142+
ResponseEntity<T[]> contents = this.rest.getForEntity(URI.create(url), type);
143143
return new StandardPage<>(Arrays.asList(contents.getBody()), () -> getPage(getNextUrl(contents), type));
144144
}
145145

@@ -169,7 +169,7 @@ public Issue removeLabel(Issue issue, String labelName) {
169169
catch (URISyntaxException ex) {
170170
throw new RuntimeException(ex);
171171
}
172-
ResponseEntity<Label[]> response = this.rest.exchange(new RequestEntity<Void>(HttpMethod.DELETE,
172+
ResponseEntity<Label[]> response = this.rest.exchange(new RequestEntity<>(HttpMethod.DELETE,
173173
URI.create(issue.getLabelsUrl().replace("{/name}", "/" + encodedName))), Label[].class);
174174
if (response.getStatusCode() != HttpStatus.OK) {
175175
log.warn("Failed to remove label from issue. Response status: " + response.getStatusCode());

Diff for: src/test/java/io/spring/issuebot/github/GitHubTemplateTests.java

+25-12
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@ void singlePageOfIssues() {
7878

7979
@Test
8080
void multiplePagesOfIssues() {
81-
HttpHeaders headers = new HttpHeaders();
82-
headers.set("Link", "<page-two>; rel=\"next\"");
8381
this.server.expect(requestTo("https://api.github.com/repos/org/repo/issues"))
8482
.andExpect(method(HttpMethod.GET))
8583
.andExpect(basicAuth())
86-
.andRespond(withResource("issues-page-one.json", "Link:<page-two>; rel=\"next\""));
84+
.andRespond(withResource("issues-page-one.json", "Link:</page-two>; rel=\"next\""));
8785
this.server.expect(requestTo("/page-two"))
8886
.andExpect(method(HttpMethod.GET))
8987
.andExpect(basicAuth())
@@ -95,6 +93,23 @@ void multiplePagesOfIssues() {
9593
assertThat(pageTwo.getContent()).hasSize(15);
9694
}
9795

96+
@Test
97+
void multiplePagesOfIssuesWithPercentEncodedLink() {
98+
this.server.expect(requestTo("https://api.github.com/repos/org/repo/issues"))
99+
.andExpect(method(HttpMethod.GET))
100+
.andExpect(basicAuth())
101+
.andRespond(withResource("issues-page-one.json", "Link:</page-two%3D%3D>; rel=\"next\""));
102+
this.server.expect(requestTo("/page-two%3D%3D"))
103+
.andExpect(method(HttpMethod.GET))
104+
.andExpect(basicAuth())
105+
.andRespond(withResource("issues-page-two.json"));
106+
Page<Issue> pageOne = this.gitHub.getIssues("org", "repo");
107+
assertThat(pageOne.getContent()).hasSize(15);
108+
Page<Issue> pageTwo = pageOne.next();
109+
assertThat(pageTwo).isNotNull();
110+
assertThat(pageTwo.getContent()).hasSize(15);
111+
}
112+
98113
@Test
99114
void rateLimited() {
100115
long reset = System.currentTimeMillis();
@@ -117,7 +132,7 @@ void noComments() {
117132
.andExpect(basicAuth())
118133
.andRespond(withSuccess("[]", MediaType.APPLICATION_JSON));
119134
Page<Comment> comments = this.gitHub
120-
.getComments(new Issue(null, "commentsUrl", null, null, null, null, null, null));
135+
.getComments(new Issue(null, "/commentsUrl", null, null, null, null, null, null));
121136
assertThat(comments.getContent()).isEmpty();
122137
assertThat(comments.next()).isNull();
123138
}
@@ -129,7 +144,7 @@ void singlePageOfComments() {
129144
.andExpect(basicAuth())
130145
.andRespond(withResource("comments-page-one.json"));
131146
Page<Comment> comments = this.gitHub
132-
.getComments(new Issue(null, "commentsUrl", null, null, null, null, null, null));
147+
.getComments(new Issue(null, "/commentsUrl", null, null, null, null, null, null));
133148
assertThat(comments.getContent()).hasSize(17);
134149
assertThat(comments.next()).isNull();
135150
}
@@ -141,13 +156,13 @@ void multiplePagesOfComments() {
141156
this.server.expect(requestTo("/commentsUrl"))
142157
.andExpect(method(HttpMethod.GET))
143158
.andExpect(basicAuth())
144-
.andRespond(withResource("comments-page-one.json", "Link:<page-two>; rel=\"next\""));
159+
.andRespond(withResource("comments-page-one.json", "Link:</page-two>; rel=\"next\""));
145160
this.server.expect(requestTo("/page-two"))
146161
.andExpect(method(HttpMethod.GET))
147162
.andExpect(basicAuth())
148163
.andRespond(withResource("comments-page-two.json"));
149164
Page<Comment> pageOne = this.gitHub
150-
.getComments(new Issue(null, "commentsUrl", null, null, null, null, null, null));
165+
.getComments(new Issue(null, "/commentsUrl", null, null, null, null, null, null));
151166
assertThat(pageOne.getContent()).hasSize(17);
152167
Page<Comment> pageTwo = pageOne.next();
153168
assertThat(pageTwo).isNotNull();
@@ -206,24 +221,22 @@ void singlePageOfEvents() {
206221
.andExpect(method(HttpMethod.GET))
207222
.andExpect(basicAuth())
208223
.andRespond(withResource("events-page-one.json"));
209-
Page<Event> events = this.gitHub.getEvents(new Issue(null, null, "eventsUrl", null, null, null, null, null));
224+
Page<Event> events = this.gitHub.getEvents(new Issue(null, null, "/eventsUrl", null, null, null, null, null));
210225
assertThat(events.getContent()).hasSize(12);
211226
assertThat(events.next()).isNull();
212227
}
213228

214229
@Test
215230
void multiplePagesOfEvents() {
216-
HttpHeaders headers = new HttpHeaders();
217-
headers.set("Link", "<page-two>; rel=\"next\"");
218231
this.server.expect(requestTo("/eventsUrl"))
219232
.andExpect(method(HttpMethod.GET))
220233
.andExpect(basicAuth())
221-
.andRespond(withResource("events-page-one.json", "Link:<page-two>; rel=\"next\""));
234+
.andRespond(withResource("events-page-one.json", "Link:</page-two>; rel=\"next\""));
222235
this.server.expect(requestTo("/page-two"))
223236
.andExpect(method(HttpMethod.GET))
224237
.andExpect(basicAuth())
225238
.andRespond(withResource("events-page-two.json"));
226-
Page<Event> pageOne = this.gitHub.getEvents(new Issue(null, null, "eventsUrl", null, null, null, null, null));
239+
Page<Event> pageOne = this.gitHub.getEvents(new Issue(null, null, "/eventsUrl", null, null, null, null, null));
227240
assertThat(pageOne.getContent()).hasSize(12);
228241
Page<Event> pageTwo = pageOne.next();
229242
assertThat(pageTwo).isNotNull();

0 commit comments

Comments
 (0)