From 7c549d45a7cc8d42d23a15562f47ec6c87bb8eb0 Mon Sep 17 00:00:00 2001 From: Thomaz Leite Date: Fri, 18 Jul 2014 20:30:43 -0300 Subject: [PATCH 1/2] Add test to catch empty string resp bug --- tests/fixtures/empty.html | 0 tests/tests.js | 10 ++++++++++ 2 files changed, 10 insertions(+) create mode 100644 tests/fixtures/empty.html diff --git a/tests/fixtures/empty.html b/tests/fixtures/empty.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/tests.js b/tests/tests.js index 663f1d7..cb56d65 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -351,6 +351,16 @@ }) }) + test('empty resp string is passed to callback', function (complete) { + ajax({ + url: '/tests/fixtures/empty.html' + , success: function (resp) { + ok(resp == '', 'resp object isn\'t empty string') + complete() + } + }) + }) + test('invalid JSON sets error on resp object', function (complete) { ajax({ url: '/tests/fixtures/invalidJSON.json' From 6e92dba8b1a418cb99e5720811de96508487757e Mon Sep 17 00:00:00 2001 From: Thomaz Leite Date: Fri, 18 Jul 2014 20:33:16 -0300 Subject: [PATCH 2/2] Fix empty string resp bug --- src/reqwest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reqwest.js b/src/reqwest.js index 00e39a8..b950f4e 100644 --- a/src/reqwest.js +++ b/src/reqwest.js @@ -293,7 +293,7 @@ } catch (e) { // can't assign this in IE<=8, just ignore } - if (r) { + if (r || r == '') { switch (type) { case 'json': try {