From cc9c86f81ba3a6ea58d216281cde665489683ada Mon Sep 17 00:00:00 2001
From: Sergiu Dumitriu <sergiu@xwiki.com>
Date: Wed, 21 Dec 2011 05:43:17 -0500
Subject: [PATCH] XWIKI-7308: Allow special (and Asian) characters in
 attachments Done.

---
 .../src/main/java/com/xpn/xwiki/web/UploadAction.java  |  5 -----
 .../wysiwyg/tinymce/wiki_editor/plugins/attachments.js | 10 +++++-----
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/UploadAction.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/UploadAction.java
index a2fc1e6f470..4529261acb5 100644
--- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/UploadAction.java
+++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/UploadAction.java
@@ -256,11 +256,6 @@ protected String getFileName(String fieldName, FileUploadPlugin fileupload, XWik
             return null;
         }
 
-        // Issues fixed by the clearName :
-        // 1) Attaching images with a name containing special characters generates bugs
-        // (image are not displayed), XWIKI-2090.
-        // 2) Attached files that we can't delete or link in the Wiki pages, XWIKI-2087.
-        filename = context.getWiki().clearName(filename, false, true, context);
         return filename;
     }
 
diff --git a/xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/js/xwiki/wysiwyg/tinymce/wiki_editor/plugins/attachments.js b/xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/js/xwiki/wysiwyg/tinymce/wiki_editor/plugins/attachments.js
index fc0363ffdcd..d86a0f16228 100644
--- a/xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/js/xwiki/wysiwyg/tinymce/wiki_editor/plugins/attachments.js
+++ b/xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/js/xwiki/wysiwyg/tinymce/wiki_editor/plugins/attachments.js
@@ -27,7 +27,7 @@ WikiEditor.prototype.ATTACHMENT_CLASS_NAME = "";
 
 WikiEditor.prototype.insertAttachment = function(editor_id, title, name) {
     var text = ((title != null) && this.trimString(title) != "") ? title : name;
-    this.core.execInstanceCommand(editor_id, "mceInsertRawHTML", false, '<a href="wikiattachment:-:' + name + '" class="' + this.ATTACHMENT_CLASS_NAME + '">' + text + '<\/a>');
+    this.core.execInstanceCommand(editor_id, "mceInsertRawHTML", false, '<a href="wikiattachment:-:' + encodeURIComponent(name) + '" class="' + this.ATTACHMENT_CLASS_NAME + '">' + text.escapeHTML() + '<\/a>');
 }
 
 WikiEditor.prototype.convertImageInternal = function(regexp, result, content) {
@@ -47,7 +47,7 @@ WikiEditor.prototype.convertImageInternal = function(regexp, result, content) {
         var imgname_reg = new RegExp(this.getImagePath().replace(/\+/g, '\\+') + "(.*)", "i");
         var r = imgname_reg.exec(href);
         if(r) {
-            var imgname = unescape(r[1]);       
+            var imgname = decodeURIComponent(r[1]);
 			str = "{image:" + imgname;
             var width=att["width"] ? this.trimString(att["width"]) : "";
 			var height=att["height"] ? this.trimString(att["height"]) : "";
@@ -136,13 +136,13 @@ WikiEditor.prototype.getAttachmentsControls = function(button_name) {
 
 WikiEditor.prototype.convertAttachmentExternal = function(regexp, result, content) {
     var href = ((typeof(result[3]) == "undefined") || (this.trimString(result[3]) == "")) ? result[1] : result[3] ;
-    var str = '<a href="wikiattachment:-:' + href + '" class="' + this.ATTACHMENT_CLASS_NAME + '">' + result[1] + '<\/a>';
+    var str = '<a href="wikiattachment:-:' + href + '" class="' + this.ATTACHMENT_CLASS_NAME + '">' + result[1].escapeHTML() + '<\/a>';
     return content.replace(regexp, str);
 }
 
 WikiEditor.prototype.convertAttachmentInternal = function(regexp, result, content) {
-    result[1] = result[1].replace(/%20/gi, " ");
-    result[3] = result[3].replace(/%20/gi, " ");
+    result[1] = decodeURIComponent(result[1].replace(/%20/gi, " "));
+    result[3] = result[3].replace(/%20/gi, " ").unescapeHTML();
     var str;
     if (result[1] == result[3]) str = "{attach:" + result[1] + "}";
     else  if ((result[1] == "undefined") || (this.trimString(result[1]) == "")) str = "{attach:" + result[3] + "}";
-- 
GitLab