From b7b115ab07297037078b08c93c8e920eb5982ae4 Mon Sep 17 00:00:00 2001 From: prusik Date: Tue, 14 Apr 2015 10:43:34 -0400 Subject: [PATCH 1/4] trim incoming data before trying to parse it as json to make sure there is something to parse. --- lib/restler.js | 2 +- test/restler.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/restler.js b/lib/restler.js index 3d7945b..66ef670 100644 --- a/lib/restler.js +++ b/lib/restler.js @@ -395,7 +395,7 @@ var parsers = { } }, json: function(data, callback) { - if (data && data.length) { + if (data && data.trim().length) { var parsedData; try { parsedData = JSON.parse(data); diff --git a/test/restler.js b/test/restler.js index ec7d926..caea497 100644 --- a/test/restler.js +++ b/test/restler.js @@ -388,6 +388,10 @@ function dataResponse(request, response) { response.writeHead(200, { 'content-type': 'application/yaml' }); response.end('{Чебурашка'); break; + case '/empty-json-trim': + response.writeHead(200, { 'content-type': 'application/json' }); + response.end(' '); + break; case '/abort': setTimeout(function() { response.writeHead(200); @@ -592,6 +596,20 @@ module.exports['Deserialization'] = { }); }, + 'Should treat trimmed empty data as a valid response': function(test) { + test.expect(2); + rest.get(host + '/empty-json-trim').on('complete', function(err, response) { + test.equal(response.raw, ' ', 'should be " ", got: ' + util.inspect(response.raw)); + test.done(); + }).on('error', function(err) { + test.ok(false, 'should not have triggered an error'); + }).on('fail', function() { + test.ok(false, 'should not have triggered a fail'); + }).on('success', function() { + test.ok(true, 'should have triggered a success'); + }); + }, + 'Should correctly handle malformed XML': function(test) { test.expect(4); rest.get(host + '/mal-xml').on('complete', function(data, response) { From 893d3ed58d4abf18f4833fb5664cfad4e583a67a Mon Sep 17 00:00:00 2001 From: prusik Date: Tue, 14 Apr 2015 13:26:03 -0400 Subject: [PATCH 2/4] updated package definition --- package.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 83143d7..ef9e392 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "restler", - "version": "3.2.2", - "description": "An HTTP client library for node.js", + "version": "3.2.3", + "description": "An HTTP client library for node.js - Unofficial Fork", "contributors": [ { "name": "Dan Webb", @@ -10,12 +10,16 @@ { "name": "Ben Marvell", "email": "ben@marvell-consulting.com" + }, + { + "name": "Shaun Moran", + "email": "smoran@prusikti.ca" } ], - "homepage": "https://github.com/danwrong/restler", + "homepage": "https://github.com/prusik/restler", "repository": { "type": "git", - "url": "https://github.com/danwrong/restler.git" + "url": "https://github.com/prusik/restler.git" }, "directories": { "lib": "./lib" From b95b68db01acd7c7f70025aa3e6528f3439aaf05 Mon Sep 17 00:00:00 2001 From: prusik Date: Thu, 9 Jul 2015 07:54:59 -0400 Subject: [PATCH 3/4] Update package.json --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ef9e392..5f19cf3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "restler", - "version": "3.2.3", - "description": "An HTTP client library for node.js - Unofficial Fork", + "version": "3.2.2", + "description": "An HTTP client library for node.js", "contributors": [ { "name": "Dan Webb", @@ -16,10 +16,10 @@ "email": "smoran@prusikti.ca" } ], - "homepage": "https://github.com/prusik/restler", + "homepage": "https://github.com/danwrong/restler", "repository": { "type": "git", - "url": "https://github.com/prusik/restler.git" + "url": "https://github.com/danwrong/restler.git" }, "directories": { "lib": "./lib" From 9bb5f10fbe2e3cdf6b9f4af2bff6bdd2f7001c7b Mon Sep 17 00:00:00 2001 From: prusik Date: Thu, 9 Jul 2015 07:55:20 -0400 Subject: [PATCH 4/4] Update package.json --- package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/package.json b/package.json index 5f19cf3..83143d7 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,6 @@ { "name": "Ben Marvell", "email": "ben@marvell-consulting.com" - }, - { - "name": "Shaun Moran", - "email": "smoran@prusikti.ca" } ], "homepage": "https://github.com/danwrong/restler",