Skip to content

Commit

Permalink
Merge pull request #253 from cyrille-leclerc/fix-infinite-loop
Browse files Browse the repository at this point in the history
Fix #252: infinite loop because the "hypertext engine" generates invalid URLs
  • Loading branch information
kohsuke committed Mar 12, 2016
2 parents dba84a3 + ba951cb commit bba07c9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -219,15 +220,19 @@ public <T> T to(String tailApiUrl, Class<T> type, String method) throws IOExcept
}

private <T> T _to(String tailApiUrl, Class<T> type, T instance) throws IOException {
while (true) {// loop while API rate limit is hit
if (METHODS_WITHOUT_BODY.contains(method) && !args.isEmpty()) {
StringBuilder qs=new StringBuilder();
for (Entry arg : args) {
qs.append(qs.length()==0 ? '?' : '&');
qs.append(arg.key).append('=').append(URLEncoder.encode(arg.value.toString(),"UTF-8"));
if (METHODS_WITHOUT_BODY.contains(method) && !args.isEmpty()) {
boolean questionMarkFound = tailApiUrl.indexOf('?') != -1;
tailApiUrl += questionMarkFound ? '&' : '?';
for (Iterator<Entry> it = args.listIterator(); it.hasNext();) {
Entry arg = it.next();
tailApiUrl += arg.key + '=' + URLEncoder.encode(arg.value.toString(),"UTF-8");
if (it.hasNext()) {
tailApiUrl += '&';
}
tailApiUrl += qs.toString();
}
}

while (true) {// loop while API rate limit is hit
setupConnection(root.getApiURL(tailApiUrl));

buildRequest();
Expand Down

0 comments on commit bba07c9

Please sign in to comment.