]> source.dussan.org Git - jgit.git/commitdiff
RefSpec: reject refs ending in '/' 33/77733/5
authorStefan Beller <sbeller@google.com>
Thu, 21 Jul 2016 21:21:57 +0000 (14:21 -0700)
committerStefan Beller <sbeller@google.com>
Mon, 25 Jul 2016 17:10:06 +0000 (10:10 -0700)
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>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java

index 4f833509d91fe793c96997c69461189c162839aa..b14b0b33476fbeac9b30e21c4a2e8a746ad5d551 100644 (file)
@@ -408,6 +408,16 @@ public class RefSpecTest {
                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)
        public void invalidWhenSourceOnlyAndWildcard() {
                assertNotNull(new RefSpec("refs/heads/*"));
index 0e803bdaf79f18120310aea5350cda55eaf50606..cbc6cc021ad93746b5e370f4119f388cc0b6e632 100644 (file)
@@ -453,6 +453,8 @@ public class RefSpec implements Serializable {
                        return false;
                if (s.contains("//")) //$NON-NLS-1$
                        return false;
+               if (s.endsWith("/")) //$NON-NLS-1$
+                       return false;
                int i = s.indexOf('*');
                if (i != -1) {
                        if (s.indexOf('*', i + 1) > i)