Commit 4a0b56fa 4a0b56fa375a6b2d788ae1c10a2f6d9496cca885 by Rajiv Kilaparti

fixes #832

1 parent 89cfda79
......@@ -1396,7 +1396,7 @@ Casper.prototype.open = function open(location, settings) {
// http data
if (settings.data) {
if (utils.isObject(settings.data)) { // query object
if (settings.headers && settings.headers["Content-Type"] === "application/json") {
if (settings.headers && settings.headers["Content-Type"].match(/application\/json/)) {
settings.data = JSON.stringify(settings.data); // convert object to JSON notation
} else {
settings.data = qs.encode(settings.data); // escapes all characters except alphabetic, decimal digits and ,-_.!~*'()
......
......@@ -130,6 +130,37 @@ casper.test.begin('open() POST json object', 2, {
}
});
casper.test.begin('open() POST json object with charset info', 2, {
setUp: setUp,
tearDown: tearDown,
test: function(test) {
casper.open('tests/site/index.html', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
data: {
plop: 42,
chuck: 'norris',
john: {'Doe': 'is here'}
}
}).then(function() {
test.pass("Casper.open() can POST a JSON object");
test.assertEquals(usedSettings, {
method: "POST",
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
data: '{"plop":42,"chuck":"norris","john":{"Doe":"is here"}}'
}, "Casper.open() used the expected POST settings");
});
casper.run(function() {
test.done();
});
}
});
casper.test.begin('open() PUT tests', 2, {
setUp: setUp,
tearDown: tearDown,
......