From 64efb89f4cf9a2c1b87803dd261688f48a421bde Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Sat, 26 Sep 2015 10:35:50 +0200 Subject: [PATCH] GitURI should not try to parse "path" part if it is missing in the URI Bug: 478464 Change-Id: I4c376c1d8df3a90ca5d59d8cfa36d2dbecab9772 Signed-off-by: Andrey Loskutov --- .../src/org/eclipse/egit/core/test/GitURITest.java | 8 ++++++++ .../src/org/eclipse/egit/core/internal/GitURI.java | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java index db560774e..0d3df1a6d 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java @@ -40,6 +40,14 @@ public class GitURITest { @SuppressWarnings("unused") @Test(expected = IllegalArgumentException.class) + public void testInvalidScmUriWithoutPath() throws Exception { + new GitURI(URI + .create("scm:git:git://git.eclipse.org/gitroot/cdo/cdo.git")); + // expected IAE, it doesn't contain semicolon and path part + } + + @SuppressWarnings("unused") + @Test(expected = IllegalArgumentException.class) public void testInvalidScmUriForCVS() throws Exception { new GitURI(URI.create("scm:cvs:pserver:dev.eclipse.org:/cvsroot/eclipse:org.eclipse.compare")); // expected IAE, it's a CVS SCM URL diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java index 525efbe22..2d21f4058 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java @@ -56,8 +56,13 @@ public class GitURI { try { if (SCHEME_SCM.equals(uri.getScheme())) { final String ssp = uri.getSchemeSpecificPart(); + int indexOfSemicolon = ssp.indexOf(';'); + if (indexOfSemicolon < 0) { + throw new IllegalArgumentException( + NLS.bind(CoreText.GitURI_InvalidSCMURL, + new String[] { uri.toString() })); + } if (ssp.startsWith(SCHEME_GIT)) { - int indexOfSemicolon = ssp.indexOf(';'); URIish r = new URIish(ssp.substring( SCHEME_GIT.length() + 1, indexOfSemicolon)); IPath p = null; -- 2.11.4.GIT