Fix spUrlToUri for path-less URLs, for root site

The root site's display URL is of the form http://host, which breaks the
assumption that the split will return four items. This was previously
unnecessary because we weren't using spUrlToUri for such URLs, but this
was changed when we fixed handling spaces in Site names.
diff --git a/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java b/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java
index cc2cfdf..de17f43 100644
--- a/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java
+++ b/src/com/google/enterprise/adaptor/sharepoint/SharePointAdaptor.java
@@ -506,12 +506,19 @@
     // turn them into URIs separately, and then turn everything into a
     // properly-escaped string.
     String[] parts = url.split("/", 4);
-    String host = parts[0] + "/" + parts[1] + "/" + parts[2] + "/";
+    if (parts.length < 3) {
+      throw new IllegalArgumentException("Too few '/'s: " + url);
+    }
+    String host = parts[0] + "/" + parts[1] + "/" + parts[2];
     // Host must be properly-encoded already.
     URI hostUri = URI.create(host);
+    if (parts.length == 3) {
+      // There was no path.
+      return hostUri;
+    }
     URI pathUri;
     try {
-      pathUri = new URI(null, null, parts[3], null);
+      pathUri = new URI(null, null, "/" + parts[3], null);
     } catch (URISyntaxException ex) {
       throw new IOException(ex);
     }
diff --git a/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java b/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java
index 1a14c13..ee15924 100644
--- a/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java
+++ b/test/com/google/enterprise/adaptor/sharepoint/SharePointAdaptorTest.java
@@ -299,6 +299,29 @@
   }
 
   @Test
+  public void testSpUrlToUriPassthrough() throws Exception {
+    assertEquals("http://somehost:1/path/file",
+        SharePointAdaptor.spUrlToUri("http://somehost:1/path/file").toString());
+  }
+
+  @Test
+  public void testSpUrlToUriSpace() throws Exception {
+    assertEquals("http://somehost/A%20space",
+        SharePointAdaptor.spUrlToUri("http://somehost/A space").toString());
+  }
+
+  @Test
+  public void testSpUrlToUriPassthroughNoPath() throws Exception {
+    assertEquals("https://somehost",
+        SharePointAdaptor.spUrlToUri("https://somehost").toString());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSpUrlToUriNoSceme() throws Exception {
+    SharePointAdaptor.spUrlToUri("http:/");
+  }
+
+  @Test
   public void testGetDocContentWrongServer() throws Exception {
     SiteDataFactory siteDataFactory = MockSiteDataFactory.blank()
         .endpoint(VS_ENDPOINT, MockSiteData.blank()