}
}
+ @Test
+ public void testInvalidTreeNameIsGITTilde1() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 GIT~1");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name 'GIT~1'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidTreeNameIsGiTTilde1() {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 GiT~1");
+ byte[] data = Constants.encodeASCII(b.toString());
+ try {
+ checker.checkTree(data);
+ fail("incorrectly accepted an invalid tree");
+ } catch (CorruptObjectException e) {
+ assertEquals("invalid name 'GiT~1'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testValidTreeNameIsGitTilde11() throws CorruptObjectException {
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 GIT~11");
+ byte[] data = Constants.encodeASCII(b.toString());
+ checker.checkTree(data);
+ }
+
@Test
public void testInvalidTreeTruncatedInName() {
final StringBuilder b = new StringBuilder();
"invalid name '%s'",
RawParseUtils.decode(raw, ptr, end)));
}
+ } else if (isGitTilde1(raw, ptr, end)) {
+ throw new CorruptObjectException(String.format("invalid name '%s'",
+ RawParseUtils.decode(raw, ptr, end)));
}
if (windows) {
&& toLower(buf[p + 2]) == 't';
}
+ private static boolean isGitTilde1(byte[] buf, int p, int end) {
+ if (end - p != 5)
+ return false;
+ return toLower(buf[p]) == 'g' && toLower(buf[p + 1]) == 'i'
+ && toLower(buf[p + 2]) == 't' && buf[p + 3] == '~'
+ && buf[p + 4] == '1';
+ }
+
private static boolean isNormalizedGit(byte[] raw, int ptr, int end) {
if (isGit(raw, ptr)) {
int dots = 0;