Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1248 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

[PATCH] Wrong default encoding breaks Internet Explorer XMLHttpRequest

Reported by: simonk Owned by: alberto
Priority: normal Milestone: 1.0.1
Component: TurboGears Version: 1.0
Severity: major Keywords:
Cc:

Description

In TG1.0b1, the default encoding if one was not specified was 'utf-8':

http://trac.turbogears.org/browser/tags/1.0b1/turbogears/controllers.py#L88

In TG1.0, it uses util.get_template_encoding_default, which returns 'utf8' (no hyphen)

http://trac.turbogears.org/browser/tags/1.0/turbogears/util.py#L370

Unfortunately, Internet Explorer doesn't parse XMLHttpRequest responses with 'charset=utf8' in the Content-type header. I think this is probably the problem that this guy is having:

 http://groups.google.com/group/turbogears/browse_thread/thread/87e019e969bfec86/f167726b52f81d50#f167726b52f81d50  http://groups.google.com/group/turbogears/browse_thread/thread/1643918bc0624c2f/b47fe5ce97fe1101#b47fe5ce97fe1101

Here is another reference about IE and 'utf8':

 http://www.panoramio.com/blog/explorer-system-error-1072896658/

The workaround is to explicitly set kid.encoding="utf-8" in your app.cfg, but it should really be fixed in util.py.

A test case is fairly simple - in a freshly quickstarted project, edit the welcome.kid template to add:

<script type="text/javascript">

function do_ajax_test() {
  d = doSimpleXMLHttpRequest('/');
  d.addCallback(ajax_test_result);
}

function ajax_test_result(result) {
  log('Received ' + repr(result));
  log('reponseText = ' + repr(result.responseText));
}

connect(window, 'onload', createLoggingPane);
connect(window, 'onload', do_ajax_test);

</script>

On firefox, the page should load and then the HTML source should be displayed in the logging pane. On IE, it says "INFO: Received undefined" but never displays the responseText line.

This is a very simple fix, and hopefully safe (the default will be the same as it was in TG1.0b1), and I think it should be fixed for 1.0.1. It is a major bug because by default it affects any XMLHttpRequest handler using a Kid template for output.

Thanks,

Simon

Attachments

utf8encoding.patch Download (1.3 KB) - added by simonk 12 years ago.
Patch against 1.0 branch (utf8 -> utf-8)

Change History

comment:1 Changed 12 years ago by alberto

Can anyone please submit a small patch for this?

Alberto

comment:2 Changed 12 years ago by simonk

That patch changes utf8 to utf-8. However, I just ran the test suite and got a few errors - let me take a look at them before you go applying it...

Changed 12 years ago by simonk

Patch against 1.0 branch (utf8 -> utf-8)

comment:3 Changed 12 years ago by simonk

Updated patch to fix the test_default_output_encoding test as well. I still get test errors but they are all to do with Catwalk, and they occur even on a fresh checkout.

Hope that helps,

Simon

comment:4 Changed 12 years ago by alberto

  • Owner changed from anonymous to alberto
  • Status changed from new to assigned
  • Summary changed from Wrong default encoding breaks Internet Explorer XMLHttpRequest to [PATCH] Wrong default encoding breaks Internet Explorer XMLHttpRequest

comment:5 Changed 12 years ago by alberto

  • Status changed from assigned to closed
  • Resolution set to fixed

Comitted at [2408]. Something must be broken in your setup, all tests pass here in a clean workingenv...

Thanks! :)

Alberto

Note: See TracTickets for help on using tickets.