Opened 9 years ago
Closed 9 years ago
#850 closed defect (fixed)
Encoding problems with JSON data
Reported by: | Nicklas Nordborg | Owned by: | Nicklas Nordborg |
---|---|---|---|
Priority: | blocker | Milestone: | Reggie v4.1.1 |
Component: | net.sf.basedb.reggie | Keywords: | |
Cc: |
Description
The Firefox update to Firefox 44.0.2 seems to have broken the encoding/decoding of JSON data that is posted between the browser and Reggie servlets. This was discovered by swedish letters åäö
being stored as åäö
.
Investigations showed that:
- Reggie sets
Content-Type: application/json
request header when posting JSON data. - Firefox 43 automatically add UTF-8 to this:
Content-Type: application/json; charset=UTF-8
- Firefox 44 doesn't add anyting
- If we don't set any
Content-Type
header at all, Firefox (both versions) automatically set:Content-Type: text/plain;charset=UTF-8
- If a charset has been set, Tomcat uses that encoding but uses Latin1 otherwise. This is what caused the corruption of swedish letters.
There are several solutions:
- We can let Reggie explicitly set
charset=UTF-8
when posting JSON data. - We can explicitly tell Tomcat to use UTF-8 when parsing the JSON data.
- Both of the above!
Change History (4)
comment:1 by , 9 years ago
Milestone: | Reggie v4.x → Reggie v4.1.1 |
---|---|
Status: | new → assigned |
comment:2 by , 9 years ago
comment:3 by , 9 years ago
comment:4 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
(In [3748]) References #850: Encoding problems with JSON data
Fixed on the server side by replacing all calls to
HttpServletRequest.getReader()
with a utility method inJsonUtil
that instead usesHttpServletRequest.getInputStream()
which is then wrapped by aReader
that is explicitely specifying 'UTF-8' encoding. In this way we do not have to rely on Tomcat to choose the encoding when converting from binary to text.