backbone icon indicating copy to clipboard operation
backbone copied to clipboard

Charset problem with Safari und Chrome

Open nischi opened this issue 13 years ago • 15 comments

Hi

In the sync function i have found a problem with charsets. Firefox and IE will send automaticly the charset, but safari and chrome not. So i have a site with utf-8 and i send new data from model to my api. an then the data will come with iso-8859-1 and that is very bad.

so now i have change following and it works for me.

from params.contentType = 'application/json'; to params.contentType = 'application/json charset=UTF-8';

i think this is correct!?

-Thierry

nischi avatar Dec 22 '12 16:12 nischi

I don't think you should need to manually send the charset. Perhaps you have a problem in your server-side configuration. Can anyone else confirm?

jashkenas avatar Dec 28 '12 02:12 jashkenas

Looking through the spec I think technically you should

@braddunbar and I were talking about maybe basing on document.characterSet and allowing an option to override?

tgriesser avatar Dec 28 '12 02:12 tgriesser

My question is -- is anyone else encountering this problem? I would have thought it would have raised it's head long ago if it's real -- I've never seen this in Backbone/Rails apps.

jashkenas avatar Dec 28 '12 02:12 jashkenas

I've never encountered it before, but all the apps I work with use UTF-8 exclusively.

braddunbar avatar Dec 28 '12 03:12 braddunbar

I can confirm the behavior - that chrome will send "Content-Type:application/json" and Firefox "Content-Type application/json; charset=UTF-8" - though based on my testing it hasn't made any difference to the data recorded on the server side nor to what gets recorded. - sending some known characters which are in UTF-8 and not in ISO-8859-1.

@nischi - do you have a test case where this causes a problem?

dekmetzi avatar Jan 11 '13 21:01 dekmetzi

Yes. I'm from Switzerland, and here we have german umlaut. Sample: Störchelstrasse

When i would transfer this string, backbone send St%A!rchelstrasse or similiar.

nischi avatar Jan 11 '13 22:01 nischi

Well you know it's interesting, in chrome dev tools it does say that that's what's being sent in the 'Request Payload', though on the server side it gets recorded just fine and gets returned fine in the response from the put request.

_test

If your code only works with the addition, maybe your server side code (or the platform you're working with) is doing some charset selection based on the 'Content-Type' header and is defaulting to ISO-8859-1 (or something else)

dekmetzi avatar Jan 11 '13 23:01 dekmetzi

But i have check the server side. thats my first idea. but there is all on utf-8. only the server it self, or the IIS make some special. But, when i put the UTF-8 manual in backbone.js, so chrome have the right chars in the Requeset Payload. So i think that would be correct. And with the manual UTF-8 in the backbone.js works in chrome and safari too. It's a little bit strange when different browser send different charsets. What do you think?

nischi avatar Jan 12 '13 07:01 nischi

Having exactly the same issue (also with swiss characters)

narenranjit avatar Jan 14 '13 19:01 narenranjit

Are you using iis as well @narenranjit ?

dekmetzi avatar Jan 14 '13 19:01 dekmetzi

i have the same issue also with tomcat from Railo 4

nischi avatar Jan 14 '13 19:01 nischi

@mdekmetzian Server: Apache/2.2.20 (Ubuntu)

narenranjit avatar Jan 14 '13 20:01 narenranjit

@nischi - my application is tomcat / jax-rs / jersey, and it works with or without the charset=UTF-8 under chrome / safari. Tested chrome under win/osx and safari on osx without issue.

I went through and reconfirmed all the above in my environment just to be sure it wasn't affecting our users, which it isnt.

@jashkenas @tgriesser I still think their issue is server-side, but at the same time, adding the charset doesn't hurt any of the above and would remove a pain point for at least some of the users.

dekmetzi avatar Jan 14 '13 22:01 dekmetzi

The server-side fix sounds correct -- and you should also be able to specify the charset in your HTML meta tags, I believe. In any case, us shoving it in the content-type seems fairly wrong -- and I can just anticipate us cutting a release with that change in there, and getting a slew of bugs from folks whose simpleminded servers don't understand a content-type so bizarre. Closing.

jashkenas avatar Mar 19 '13 12:03 jashkenas

Just try setting the content-type in client request instead of trying at server. That solved my problem. And I guess that is correct because the client should decide what encoding he should sent.

saji-v avatar Jun 27 '13 05:06 saji-v