#1090: Safari XMLHttpRequest "fix" breaks JSON & other output
------------------------+---------------------------------------------------
 Reporter:  FCodyC      |       Owner:  anonymous
     Type:  defect      |      Status:  new      
 Priority:  high        |   Milestone:           
Component:  TurboGears  |     Version:  0.9a5    
 Severity:  normal      |    Keywords:  safari   
------------------------+---------------------------------------------------
 I've done some testing with Safari and XMLHttpRequest, and here's what
 I've found.

 1) Safari honors META tags' Content-Type attribute for character encoding.
 If you set it to "text/html; charset=utf8", (or your encoding of choice)
 non-ascii characters get displayed properly.

 2) Safari honors HTTP Content-Type headers.  If you set Content-Type here
 as above, Safari will render non-ascii characters properly.

 3) For the URL of the current page, given no encodings in either HTTP
 headers or HTML META tags, Safari does some magic and still manages to
 display characters properly.

 BUT: Here's where Safari seems to differ from Firefox and IE:

 4) If a page is requested via XMLHttpRequest and it has no defined
 encoding in either HTTP or HTML, the charset is assumed latin1.

 All that being said, the fix currently in place needs to be rewritten,
 because it actually introduces a rather annoying bug:

 From trunk:
     if ua.browser == "safari":
         if isinstance(output, str):
             output = output.decode(enc)
         output = unicodechars.sub(
             lambda m: "&#x%x;" % ord(m.group(1)), output).encode("ascii")

 For all Content-Types that begin with "text/", this is encoding unicode
 characters as XML/HTML entities.  That's not very appropriate for
 text/plain or text/x-json.  I've seen many references to this "Safari
 bug".  Why HTML entities would show up in JSON data is pretty confusing.

 The fix is just to include the text-encoding in the Content-Type HTTP
 header if it's not currently present.  (And to respect it if it IS
 present.)

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/1090>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-tickets
-~----------~----~----~----~------~----~------~--~---

Reply via email to