[Greasemonkey] Javascript character encoding problem

Jonas Lundberg my.name.is.hans at gmail.com
Fri Apr 14 00:04:33 EDT 2006


This simplified test case should show the bug, if indeed it is not all
my computers playing tricks with me:

function send(data) {
GM_xmlhttpRequest({
method: 'POST',
url: mysubmit,
headers: {
'Content-type': 'multipart/form-data; boundary=shapecms',
},
data: data,
onload: function(responseDetails) {
var ok = '200';
if(responseDetails.status == ok) {
}
else {
GM_log('error message:'+responseDetails.responseText);
}
GM_log(responseDetails.responseText);
}
}) };

A typical ok input to this function (the "data") would be:
var content = '--shapecms\r\nContent-Disposition: form-data;
name="visited"\r\n\r\ntrue\r\n--shapecms--'

One which will not work (because of the encoding bug would be)
var content = '--shapecms\r\nContent-Disposition: form-data;
name="visited"\r\n\r\nÅÄÖåäö\r\n--shapecms--'

(Since character ecodings can go wrong through email as well, I'd like
to add that the characters you *should* here see are first an A with a
ring, then an A with two dots, then an O with two dots)

I use the LiveHTTPheaders extension to inspect the data as it is sent,
and then I see that these internatioal characters are corrupted in the
Ajax call.

You also have to set the "mysubmit" variable to a server somewhere.

It would be really great if someone knows how to fix this!

Hans

--------------------------------------------------

On 4/13/06, Jeremy Dunck <jdunck at gmail.com> wrote:
> On 4/13/06, Jonas Lundberg <my.name.is.hans at gmail.com> wrote:
> > It is definitely a bug, according to the w3c draft, the xmlhttprequest
> > encoding is not correct.
>
>
> Could you do me a favor and create a few test files in the encodings
> you're dealing with?
>
> I pretty well understand encoding, but I'm always afraid the tools are
> lying to me. UltraEdit (otherwise a good editor) is braindead when
> dealing with Unicode, for example.
>
> Just name them utf8.html, etc, and pass them along. Save As... might
> work, except that I don't know whether the browser canonicalizes to a
> particular encoding when saving to disk....
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list