Reviewed by Chris.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Sep 2004 20:41:23 +0000 (20:41 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Sep 2004 20:41:23 +0000 (20:41 +0000)
        - fixed <rdar://problem/3410112> filename with non-ASCII name for <input type=file> should be sent in the page's encoding

        * khtml/html/html_formimpl.cpp: (DOM::HTMLFormElementImpl::formData):
        Encode filename using the codec rather than doing the &# dance. It turns out that Mozilla
        only does the &# thing under certain circumstances that are not important. Always encoding
        the filename is almost certainly better behavior, and will fix many serious problems for
        Japanese and Korean users and websites.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@7447 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/html/html_formimpl.cpp

index 190168554d6e7a9faef8a0f446e2b7ca702b43ba..8dbb3d8225e262746e80d41f2fb8adf20bfe6f37 100644 (file)
@@ -1,3 +1,15 @@
+2004-09-03  Darin Adler  <darin@apple.com>
+
+        Reviewed by Chris.
+
+        - fixed <rdar://problem/3410112> filename with non-ASCII name for <input type=file> should be sent in the page's encoding
+
+        * khtml/html/html_formimpl.cpp: (DOM::HTMLFormElementImpl::formData):
+        Encode filename using the codec rather than doing the &# dance. It turns out that Mozilla
+        only does the &# thing under certain circumstances that are not important. Always encoding
+        the filename is almost certainly better behavior, and will fix many serious problems for
+        Japanese and Korean users and websites.
+
 2004-09-03  Darin Adler  <darin@apple.com>
 
         Reviewed by John.
index 6dd184524249fc4bf050594bb4372dcd163bdfdc..ce631ea5a1e278ce5de09ca9fef5dbda182d3124 100644 (file)
@@ -343,7 +343,9 @@ bool HTMLFormElementImpl::formData(FormData &form_data) const
     if(!codec)
         codec = QTextCodec::codecForLocale();
 
+#if !APPLE_CHANGES
     QStringList fileUploads;
+#endif
 
     for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it) {
         HTMLGenericFormElementImpl* current = it.current();
@@ -387,30 +389,22 @@ bool HTMLFormElementImpl::formData(FormData &form_data) const
                         static_cast<HTMLInputElementImpl*>(current)->inputType() == HTMLInputElementImpl::FILE)
                     {
                         QString path = static_cast<HTMLInputElementImpl*>(current)->value().string();
+#if !APPLE_CHANGES
                         if (path.length()) fileUploads << path;
-
-                        // Turn non-ASCII characters into &-escaped form.
-                        // This doesn't work perfectly, because it doesn't escape &, for example.
-                        // But it seems to be what Gecko does.
-                        QString onlyfilename;
-                        for (uint i = path.findRev('/') + 1; i < path.length(); ++i) {
-                            QChar c = path.at(i).unicode();
-                            if (c.unicode() >= 0x20 && c.unicode() <= 0x7F) {
-                                onlyfilename.append(&c, 1);
-                            } else {
-                                QString ampersandEscape;
-                                ampersandEscape.sprintf("&#%hu;", c.unicode());
-                                onlyfilename.append(ampersandEscape);
-                            }
-                        }
+#endif
 
                         // FIXME: This won't work if the filename includes a " mark,
-                        // or control characters like CR or LF.
-                        hstr += ("; filename=\"" + onlyfilename + "\"").ascii();
+                        // or control characters like CR or LF. This also does strange
+                        // things if the filename includes characters you can't encode
+                        // in the website's character set.
+                        hstr += "; filename=\"";
+                        hstr += codec->fromUnicode(path.mid(path.findRev('/') + 1));
+                        hstr += "\"";
+
                         if(!static_cast<HTMLInputElementImpl*>(current)->value().isEmpty())
                         {
 #if APPLE_CHANGES
-                            QString mimeType = part ? KWQ(part)->mimeTypeForFileName(onlyfilename) : QString();
+                            QString mimeType = part ? KWQ(part)->mimeTypeForFileName(path) : QString();
 #else
                             KMimeType::Ptr ptr = KMimeType::findByURL(KURL(path));
                             QString mimeType = ptr->name();