Bladeren bron

RefSpec: reject refs ending in '/'

We had a case in Gerrits superproject subscriptions where
'refs/heads/' was configured with the intention to mean 'refs/heads/*'.

The first expression lacks the '*', which is why it is not considered
a wildcard but it was considered valid and so was not found early to be
a typo.

Refs are not allowed to end with '/' anyway, so add a check for that.

Change-Id: I3ffdd9002146382acafb4fbc310a64af4cc1b7a9
Signed-off-by: Stefan Beller <sbeller@google.com>
tags/v4.5.0.201609210915-r
Stefan Beller 8 jaren geleden
bovenliggende
commit
1556ca740b

+ 10
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java Bestand weergeven

assertEquals("foo/head", c.getSource()); assertEquals("foo/head", c.getSource());
} }


@Test(expected = IllegalArgumentException.class)
public void invalidWhenSourceEndsWithSlash() {
assertNotNull(new RefSpec("refs/heads/"));
}

@Test(expected = IllegalArgumentException.class)
public void invalidWhenDestinationEndsWithSlash() {
assertNotNull(new RefSpec("refs/heads/master:refs/heads/"));
}

@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void invalidWhenSourceOnlyAndWildcard() { public void invalidWhenSourceOnlyAndWildcard() {
assertNotNull(new RefSpec("refs/heads/*")); assertNotNull(new RefSpec("refs/heads/*"));

+ 2
- 0
org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java Bestand weergeven

return false; return false;
if (s.contains("//")) //$NON-NLS-1$ if (s.contains("//")) //$NON-NLS-1$
return false; return false;
if (s.endsWith("/")) //$NON-NLS-1$
return false;
int i = s.indexOf('*'); int i = s.indexOf('*');
if (i != -1) { if (i != -1) {
if (s.indexOf('*', i + 1) > i) if (s.indexOf('*', i + 1) > i)

Laden…
Annuleren
Opslaan