diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 224167b99c14baaad794ec9ebea81aca7810fd52..06d193bf8f387b187056541f65b95019f4fd9aca 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -960,7 +960,7 @@ function getMimeIcon(mime, ready){
 getMimeIcon.cache={};
 
 function getPreviewIcon(path, ready){
-	ready(OC.Router.generate('core_ajax_preview', {file:path, x:44, y:44}));
+	ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:44, y:44}));
 }
 
 function getUniqueName(name){
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index e82a597c61ef33e5e7d6b52b2c91959f39f5a7a9..fb99fca5b3fdaf24c0c94f1ff5182277cf22efad 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -852,6 +852,6 @@ class Trashbin {
 	}
 
 	public static function preview_icon($path) {
-		return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => $path));
+		return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) ));
 	}
 }
diff --git a/lib/helper.php b/lib/helper.php
index 0a8962a5312c5b825110338418c23a662e9a3ebb..326f2567f99b6527b4b6b4231676ea0c6340b27c 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -231,7 +231,7 @@ class OC_Helper {
 	 * Returns the path to the preview of the file.
 	 */
 	public static function previewIcon($path) {
-		return self::linkToRoute( 'core_ajax_preview', array('x' => 44, 'y' => 44, 'file' => $path));
+		return self::linkToRoute( 'core_ajax_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) ));
 	}
 
 	/**