Bug 108400 - XMLHttpRequest doesn't handle document charset
Summary: XMLHttpRequest doesn't handle document charset
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-01 14:43 UTC by Michael Krelin
Modified: 2005-09-25 16:52 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
xmlhttprequest.diff (913 bytes, text/x-diff)
2005-07-15 00:58 UTC, Dawit Alemayehu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Krelin 2005-07-01 14:43:33 UTC
Version:            (using KDE KDE 3.4.1)
Installed from:    Gentoo Packages
Compiler:          gcc 3 
OS:                Linux

When I am trying to load an html fragment via XMLHttpRequest() and display it via *.innerHTML = *.responseText it shows up, I believe, in Latin encoding. Which is not the case for Firefox, MSIE and Opera.

You can check out the behaviour at 

http://hacker.klever.net/range/konqueror-charset-bug/

which loads http://hacker.klever.net/range/konqueror-charset-bug/to-load.html

Both documents return Content-Type: text/html; charset=windows-1251
Comment 1 Thiago Macieira 2005-07-02 02:48:52 UTC
I can reproduce (trunk 424191).
Comment 2 Dawit Alemayehu 2005-07-15 00:58:56 UTC
The attached patch should fix the problem. 

On Friday 01 July 2005 20:48, Thiago Macieira wrote:
[bugs.kde.org quoted mail]


Created an attachment (id=11811)
xmlhttprequest.diff
Comment 3 Thiago Macieira 2005-07-15 03:31:30 UTC
I can confirm it fixes the problem. If you'll be so kind, Dawit, commit it :-)
Comment 4 Michael Krelin 2005-07-15 13:42:40 UTC
Great, I've seen you working in the logs ;-)

Hope it's okay if I eventually remove the files I've put on the web.
Comment 5 Dawit Alemayehu 2005-07-15 15:48:09 UTC
SVN commit 434817 by adawit:

- Use the charset provided by the remote host through the HTTP headers.

BUG: 108400@bugs.kde.org



 M  +12 -0     xmlhttprequest.cpp  


--- trunk/KDE/kdelibs/khtml/ecma/xmlhttprequest.cpp #434816:434817
@@ -553,6 +553,18 @@
 #endif
 
   if ( decoder == NULL ) {
+     int pos = responseHeaders.find("Content-Type:");
+     if ( pos > -1 )
+     {
+        int index = responseHeaders.find('\n', pos+13);
+        QString type = responseHeaders.mid(pos+13, index);
+        // qDebug("XMLHttpRequest::slotData: 'content-type = %s'", type.latin1());
+        index = type.find (';');
+        if (index > -1)
+          encoding = type.mid( index+1 ).remove(QRegExp("charset[ ]*=[ ]*", false)).stripWhiteSpace();
+        // qDebug("XMLHttpRequest::slotData: 'encoding = %s'", encoding.latin1());
+     }
+
     decoder = new Decoder;
     if (!encoding.isNull())
       decoder->setEncoding(encoding.latin1(), Decoder::EncodingFromHTTPHeader);
Comment 6 Anton 2005-09-25 16:52:53 UTC
guys, your patch doesn't work for me.
Please double check.

Cheers,
Anton

ps. I think you have to apply it "encoding" after 
if (!encoding.isNull()) 
        decoder->setEncoding(encoding.latin1(), Decoder::EncodingFromHTTPHeader); 

In the "fixme" line.