Browse Source

Throw URISyntaxException for incorrect percent-encoding

URIish.unescape() threw an ArrayIndexOutOfBoundsException if the given
url has incorrect percent-encoding (e.g. http://example.com/%gg). But an
URISyntaxException is much better to know the reason of the failure.

Change-Id: I3f40a26d43cd2eb4e32c11aba7dc2594bc1f98e2
Signed-off-by: Yi EungJun <eungjun.yi@navercorp.com>
tags/v3.5.0.201409071800-rc1
Yi EungJun 9 years ago
parent
commit
da6e729086
1 changed files with 13 additions and 2 deletions
  1. 13
    2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

+ 13
- 2
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java View File

@@ -252,6 +252,11 @@ public class URIish implements Serializable {
throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
}

private static int parseHexByte(byte c1, byte c2) {
return ((RawParseUtils.parseHexInt4(c1) << 4)
| RawParseUtils.parseHexInt4(c2));
}

private static String unescape(String s) throws URISyntaxException {
if (s == null)
return null;
@@ -272,8 +277,14 @@ public class URIish implements Serializable {
if (c == '%') {
if (i + 2 >= bytes.length)
throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
int val = (RawParseUtils.parseHexInt4(bytes[i + 1]) << 4)
| RawParseUtils.parseHexInt4(bytes[i + 2]);
byte c1 = bytes[i + 1];
byte c2 = bytes[i + 2];
int val;
try {
val = parseHexByte(c1, c2);
} catch (ArrayIndexOutOfBoundsException e) {
throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
}
os[j++] = (byte) val;
i += 2;
} else

Loading…
Cancel
Save