From 44c9d8937a4168abbdcc9495dc390fe47b24e469 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Mon, 22 Oct 2007 11:20:21 +0000 Subject: [PATCH] prototype: Make the Ajax.Response#headerJSON property correctly decode unicode characters. Closes #9285 --- CHANGELOG | 2 ++ src/ajax.js | 4 +++- test/unit/ajax.html | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 505f8f0..86b6be3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make the Ajax.Response#headerJSON property correctly decode unicode characters. Closes #9285. [Marius Feraru, Tobie Langel] + * Make sure Event and Event.extend are defined before wrapping events and calling their handler. Prevents a known Firefox bug from throwing errors on page load/unload (cf.: https://bugzilla.mozilla.org/show_bug.cgi?id=361271). Closes #5393, #9421. [staaky, John Resig, sam, Tobie Langel] * Minor cosmetic changes to the display of unit tests in terminal. [Tobie Langel] diff --git a/src/ajax.js b/src/ajax.js index 22c2bb3..bea5d9a 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -276,8 +276,10 @@ Ajax.Response = Class.create({ _getHeaderJSON: function() { var json = this.getHeader('X-JSON'); + if (!json) return null; + json = decodeURIComponent(escape(json)); try { - return json ? json.evalJSON(this.request.options.sanitizeJSON) : null; + return json.evalJSON(this.request.options.sanitizeJSON); } catch (e) { this.request.dispatchException(e); } diff --git a/test/unit/ajax.html b/test/unit/ajax.html index 0bf782f..c2aa9ba 100644 --- a/test/unit/ajax.html +++ b/test/unit/ajax.html @@ -60,7 +60,7 @@ }, headerJson: { - 'X-JSON': '{"test": 123}' + 'X-JSON': '{"test": "hello #éà"}' } }; @@ -347,8 +347,8 @@ new Ajax.Request("/response", extendDefault({ parameters: Fixtures.headerJson, onComplete: function(transport, json) { - assertEqual(123, transport.headerJSON.test); - assertEqual(123, json.test); + assertEqual('hello #éà', transport.headerJSON.test); + assertEqual('hello #éà', json.test); } }));