Index: src/wp-includes/ms-blogs.php
===================================================================
--- src/wp-includes/ms-blogs.php	(revision 30382)
+++ src/wp-includes/ms-blogs.php	(working copy)
@@ -296,9 +296,15 @@
 
 	$update_details = array();
 	$fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
-	foreach ( array_intersect( array_keys( $details ), $fields ) as $field )
-		$update_details[$field] = $details[$field];
+	foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
+		if ( 'path' === $field ) {
+			$details[ $field ] = array_filter( explode( '/', $details[ $field ] ) );
+			$details[ $field ] = trailingslashit( '/' . implode( '/', $details[ $field ] ) );
+		}
 
+		$update_details[ $field ] = $details[ $field ];
+	}
+
 	$result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
 
 	if ( false === $result )
Index: tests/phpunit/tests/multisite/site.php
===================================================================
--- tests/phpunit/tests/multisite/site.php	(revision 30382)
+++ tests/phpunit/tests/multisite/site.php	(working copy)
@@ -293,26 +293,26 @@
 		$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
 		$this->assertInternalType( 'int', $blog_id );
 
-		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path/') );
+		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => '/my_path/') );
 		$this->assertTrue( $result );
 
 		$blog = get_blog_details( $blog_id );
 		$this->assertEquals( 'example.com', $blog->domain );
-		$this->assertEquals( 'my_path/', $blog->path );
+		$this->assertEquals( '/my_path/', $blog->path );
 		$this->assertEquals( '0', $blog->spam );
 
 		$result = update_blog_details( $blog_id, array('domain' => 'example2.com','spam' => 1) );
 		$this->assertTrue( $result );
 		$blog = get_blog_details( $blog_id );
 		$this->assertEquals( 'example2.com', $blog->domain );
-		$this->assertEquals( 'my_path/', $blog->path );
+		$this->assertEquals( '/my_path/', $blog->path );
 		$this->assertEquals( '1', $blog->spam );
 
 		$result = update_blog_details( $blog_id );
 		$this->assertFalse( $result );
 		$blog = get_blog_details( $blog_id );
 		$this->assertEquals( 'example2.com', $blog->domain );
-		$this->assertEquals( 'my_path/', $blog->path );
+		$this->assertEquals( '/my_path/', $blog->path );
 		$this->assertEquals( '1', $blog->spam );
 
 		$test_action_counter = 0;
@@ -444,6 +444,43 @@
 	}
 
 	/**
+	 * Check the path for a sub-directory site is correctly sanitised, 
+	 * and has a trailing slash. 
+	 * 
+	 * @ticket 18117 
+	 */ 
+	function test_update_blog_sanitises_subdirectory_path() {
+
+		$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
+		$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
+		$this->assertInternalType( 'int', $blog_id );
+
+		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path') );
+		$blog = get_blog_details( $blog_id );
+		$this->assertEquals( '/my_path/', $blog->path );
+
+		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path//') );
+		$blog = get_blog_details( $blog_id );
+		$this->assertEquals( '/my_path/', $blog->path );
+
+		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => '//my_path') );
+		$blog = get_blog_details( $blog_id );
+		$this->assertEquals( '/my_path/', $blog->path );
+
+		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => '/my_path') );
+		$blog = get_blog_details( $blog_id );
+		$this->assertEquals( '/my_path/', $blog->path );
+
+		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'multiple/dirs') );
+		$blog = get_blog_details( $blog_id );
+		$this->assertEquals( '/multiple/dirs/', $blog->path );
+
+		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'multiple///dirs') );
+		$blog = get_blog_details( $blog_id );
+		$this->assertEquals( '/multiple/dirs/', $blog->path );
+	}
+
+	/**
 	 * Test cached data for a site that does not exist and then again after it exists.
 	 *
 	 * @ticket 23405
