File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,23 @@ Ajax.Response = Class.create({
151
151
_getHeaderJSON : function ( ) {
152
152
var json = this . getHeader ( 'X-JSON' ) ;
153
153
if ( ! json ) return null ;
154
- json = decodeURIComponent ( escape ( json ) ) ;
154
+
155
+ try {
156
+ // Browsers expect HTTP headers to be ASCII and nothing else. Running
157
+ // them through `decodeURIComponent` processes them with the page's
158
+ // specified encoding.
159
+ json = decodeURIComponent ( escape ( json ) ) ;
160
+ } catch ( e ) {
161
+ // Except Chrome doesn't seem to need this, and calling
162
+ // `decodeURIComponent` on text that's already in the proper encoding
163
+ // will throw a `URIError`. The ugly solution is to assume that a
164
+ // `URIError` raised here signifies that the text is, in fact, already
165
+ // in the correct encoding, and treat the failure as a good sign.
166
+ //
167
+ // This is ugly, but so too is sending extended characters in an HTTP
168
+ // header with no spec to back you up.
169
+ }
170
+
155
171
try {
156
172
return json . evalJSON ( this . request . options . sanitizeJSON ||
157
173
! this . request . isSameOrigin ( ) ) ;
You can’t perform that action at this time.
0 commit comments