Bug 131242 - xmlhttprequest breaks on utf-8 strings
Summary: xmlhttprequest breaks on utf-8 strings
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: kjs (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-23 16:24 UTC by Rob Kaper
Modified: 2006-08-24 16:19 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Patch (fixes test case for me) (538 bytes, patch)
2006-08-23 23:34 UTC, James Thorniley
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Kaper 2006-07-23 16:24:01 UTC
Version:           3.5.3 (using KDE 3.5.3, compiled sources)
Compiler:          gcc version 3.4.6
OS:                Linux (i686) release 2.4.31

Might be related to #130234, not sure.

XmlHttpRequests containing UTF-8 POST data are not sent correctly. A simple testcase is available here:

http://www.robertjohnkaper.com/tmp/kio_utf8.html

Works fine in Firefox, but Konqueror messes up and loses input data.
Comment 1 Jan Mentzel 2006-07-29 16:00:46 UTC
Version:   3.5.3 (using KDE 3.5.3)
Compiler:  gcc (GCC) 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)
OS:        Linux i686 2.6.17-ck1-r2 #1 PREEMPT

Same problem here with german "Umlaute".

Seems to me as there runs something wrong when konqueror calculates the string length of the utf-8 encoded string.

Same problem occures in Safari-2.0.4 if in the request the content-type header is set to something different from "text/javascript".
Comment 2 Jiri Kaderavek 2006-08-08 11:26:15 UTC
Duplicate bug #119391
Comment 3 James Thorniley 2006-08-23 23:34:54 UTC
Created attachment 17476 [details]
Patch (fixes test case for me)

Attached patch fixes the issue for me
Comment 4 Jan Mentzel 2006-08-24 14:51:44 UTC
Patch fixes issue for me too.
Comment 5 Germain Garand 2006-08-24 15:36:38 UTC
SVN commit 576640 by ggarand:

apply patch by James Thorniley<james_thorniley@yahoo.co.uk>

for "xmlhttprequest breaks on utf-8 strings"

BUG:131242



 M  +1 -1      xmlhttprequest.cpp  


--- branches/KDE/3.5/kdelibs/khtml/ecma/xmlhttprequest.cpp #576639:576640
@@ -335,7 +335,7 @@
     // FIXME: determine post encoding correctly by looking in headers
     // for charset.
     QByteArray buf;
-    buf.duplicate(_body.utf8().data(), _body.length());
+    buf.duplicate(_body.utf8().data(), _body.utf8().length());
 
     job = KIO::http_post( url, buf, false );
     if(contentType.isNull())
Comment 6 David Faure 2006-08-24 16:19:52 UTC
SVN commit 576656 by dfaure:

Calling utf8() twice is expensive, calling length() on a QCString is expensive, so better not do either one :)
CCBUG: 131242


 M  +2 -1      xmlhttprequest.cpp  


--- branches/KDE/3.5/kdelibs/khtml/ecma/xmlhttprequest.cpp #576655:576656
@@ -335,7 +335,8 @@
     // FIXME: determine post encoding correctly by looking in headers
     // for charset.
     QByteArray buf;
-    buf.duplicate(_body.utf8().data(), _body.utf8().length());
+    QCString str = _body.utf8();
+    buf.duplicate(str.data(), str.size() - 1);
 
     job = KIO::http_post( url, buf, false );
     if(contentType.isNull())