From 5334cb8688aa627c3ada1186902ec9e5ff342f92 Mon Sep 17 00:00:00 2001 From: Ben Sheats Date: Fri, 21 Oct 2016 11:40:01 -0400 Subject: [PATCH 1/2] url encode hashes in ref names --- src/main/java/org/kohsuke/github/GHRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 472adf41e..beba889f5 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -765,6 +765,8 @@ public class GHRepository extends GHObject { * invalid ref type being requested */ public GHRef getRef(String refName) throws IOException { + // hashes in branch names must be replaced with the url encoded equivalent or this call will fail + refName = refName.replaceAll("#", "%23"); return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class).wrap(root); } /** From 4965fd5f4cdf90e1dc8ded82f214a3ddf2479c6d Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 24 Oct 2016 19:15:38 -0700 Subject: [PATCH 2/2] Noting possible TODO for the future --- src/main/java/org/kohsuke/github/GHRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index beba889f5..2a16feb2f 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -766,6 +766,8 @@ public class GHRepository extends GHObject { */ public GHRef getRef(String refName) throws IOException { // hashes in branch names must be replaced with the url encoded equivalent or this call will fail + // FIXME: how about other URL unsafe characters, like space, @, : etc? do we need to be using URLEncoder.encode()? + // OTOH, '/' need no escaping refName = refName.replaceAll("#", "%23"); return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class).wrap(root); }