Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag-and-drop upload of a file with "&" in its name fails #26

Open
stezadov opened this issue Oct 10, 2016 · 1 comment
Open

Drag-and-drop upload of a file with "&" in its name fails #26

stezadov opened this issue Oct 10, 2016 · 1 comment

Comments

@stezadov
Copy link
Contributor

Drag-and-drop upload of a file with "&" in its name fails. Though files selected via system file selection dialog upload fine.
This is due to lack of escaping in XML response from the server.
I first tried to work around it via this change:

--- a/<html>UploadServlet.java (<b>Oct 6, 2016 11:49:06 AM</b>)</html>
+++ b/<html><b>Current File</b></html>
@@ -770,7 +770,8 @@
     Map<String, String> item = new HashMap<String, String>();
     item.put(TAG_CTYPE, i.getContentType() !=null ? i.getContentType() : "unknown");
     item.put(TAG_SIZE, "" + i.getSize());
-    item.put(TAG_NAME, "" + i.getName());
+    //item.put(TAG_NAME, "" + i.getName());
+    item.put(TAG_NAME, "<![CDATA[" + i.getName() + "]]>");
     item.put(TAG_FIELD, "" + i.getFieldName());
     if (i instanceof HasKey) {
       String k = ((HasKey)i).getKeyString();

It fixed upload of DnD selected files but spoiled file names by replacing "&" with "&" for files selected via system dialog.
To work around that second issue I applied this fix:

--- a/<html>Uploader.java (<b>Oct 6, 2016 11:49:06 AM</b>)</html>
+++ b/<html><b>Current File</b></html>
@@ -435,7 +435,7 @@
       serverRawResponse = event.getResults();
       if (serverRawResponse != null) {
         serverRawResponse = serverRawResponse.replaceFirst(".*" + TAG_MSG_START + "([\\s\\S]*?)" + TAG_MSG_END + ".*", "$1");
-        serverRawResponse = serverRawResponse.replace(TAG_MSG_LT, "<").replace(TAG_MSG_GT, ">").replace("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&nbsp;", " ");
+        serverRawResponse = serverRawResponse.replace(TAG_MSG_LT, "<").replace(TAG_MSG_GT, ">").replace("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&nbsp;", " ").replace("&amp;", "&");
       }
       try {
         // Parse the xml and extract UploadedInfos

Now it works as expected though that second piece of code looks strange unescaping XML char references before passing the XML to the parser. I actually see similar concern has been raised before here: #22 .

@csware csware mentioned this issue Mar 31, 2017
@csware
Copy link
Contributor

csware commented Feb 14, 2021

Can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants