Commit 38435be8 38435be89aa10f3304d747c1ec34a6d1f75fb886 by Nicolas Perriault

Merge pull request #840 from r8k/master

fixes #832 #196
2 parents b00b295f 7646ea06
......@@ -1397,7 +1397,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,
......