diff --git a/lib/public/share.php b/lib/public/share.php
index 91b0ef6dc695dd2ee1a436ffddc486c19338e5ab..7a8a183574bd892ff121f86a8775d8c3af972ed5 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -293,7 +293,18 @@ class Share {
 		if (\OC_DB::isError($result)) {
 			\OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result) . ', token=' . $token, \OC_Log::ERROR);
 		}
-		return $result->fetchRow();
+		$row = $result->fetchRow();
+
+		if (!empty($row['expiration'])) {
+			$now = new \DateTime();
+			$expirationDate = new \DateTime($row['expiration'], new \DateTimeZone('UTC'));
+			if ($now > $expirationDate) {
+				self::delete($row['id']);
+				return false;
+			}
+		}
+
+		return $row;
 	}
 
 	/**
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index e02b0e4354d1bda4c359895afe328439cf74d7d0..8e9eef65d320fad8bb5d8f4af1211f78c9ae0fb0 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -535,4 +535,52 @@ class Test_Share extends PHPUnit_Framework_TestCase {
 			'Failed asserting that user 3 still has access to test.txt after expiration date has been set.'
 		);
 	}
+
+	protected function getShareByValidToken($token) {
+		$row = OCP\Share::getShareByToken($token);
+		$this->assertInternalType(
+			'array',
+			$row,
+			"Failed asserting that a share for token $token exists."
+		);
+		return $row;
+	}
+
+	public function testShareItemWithLink() {
+		OC_User::setUserId($this->user1);
+		$token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, OCP\PERMISSION_READ);
+		$this->assertInternalType(
+			'string',
+			$token,
+			'Failed asserting that user 1 successfully shared text.txt as link with token.'
+		);
+
+		// testGetShareByTokenNoExpiration
+		$row = $this->getShareByValidToken($token);
+		$this->assertEmpty(
+			$row['expiration'],
+			'Failed asserting that the returned row does not have an expiration date.'
+		);
+
+		// testGetShareByTokenExpirationValid
+		$this->assertTrue(
+			OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
+			'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.'
+		);
+		$row = $this->getShareByValidToken($token);
+		$this->assertNotEmpty(
+			$row['expiration'],
+			'Failed asserting that the returned row has an expiration date.'
+		);
+
+		// testGetShareByTokenExpirationExpired
+		$this->assertTrue(
+			OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
+			'Failed asserting that user 1 successfully set a past expiration date for the test.txt share.'
+		);
+		$this->assertFalse(
+			OCP\Share::getShareByToken($token),
+			'Failed asserting that an expired share could not be found.'
+		);
+	}
 }