Merge pull request #840 from r8k/master
fixes #832 #196
Showing
2 changed files
with
32 additions
and
1 deletions
... | @@ -1397,7 +1397,7 @@ Casper.prototype.open = function open(location, settings) { | ... | @@ -1397,7 +1397,7 @@ Casper.prototype.open = function open(location, settings) { |
1397 | // http data | 1397 | // http data |
1398 | if (settings.data) { | 1398 | if (settings.data) { |
1399 | if (utils.isObject(settings.data)) { // query object | 1399 | if (utils.isObject(settings.data)) { // query object |
1400 | if (settings.headers && settings.headers["Content-Type"] === "application/json") { | 1400 | if (settings.headers && settings.headers["Content-Type"].match(/application\/json/)) { |
1401 | settings.data = JSON.stringify(settings.data); // convert object to JSON notation | 1401 | settings.data = JSON.stringify(settings.data); // convert object to JSON notation |
1402 | } else { | 1402 | } else { |
1403 | settings.data = qs.encode(settings.data); // escapes all characters except alphabetic, decimal digits and ,-_.!~*'() | 1403 | 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, { | ... | @@ -130,6 +130,37 @@ casper.test.begin('open() POST json object', 2, { |
130 | } | 130 | } |
131 | }); | 131 | }); |
132 | 132 | ||
133 | casper.test.begin('open() POST json object with charset info', 2, { | ||
134 | setUp: setUp, | ||
135 | tearDown: tearDown, | ||
136 | test: function(test) { | ||
137 | casper.open('tests/site/index.html', { | ||
138 | method: 'POST', | ||
139 | headers: { | ||
140 | 'Content-Type': 'application/json; charset=utf-8' | ||
141 | }, | ||
142 | data: { | ||
143 | plop: 42, | ||
144 | chuck: 'norris', | ||
145 | john: {'Doe': 'is here'} | ||
146 | } | ||
147 | }).then(function() { | ||
148 | test.pass("Casper.open() can POST a JSON object"); | ||
149 | test.assertEquals(usedSettings, { | ||
150 | method: "POST", | ||
151 | headers: { | ||
152 | 'Content-Type': 'application/json; charset=utf-8' | ||
153 | }, | ||
154 | data: '{"plop":42,"chuck":"norris","john":{"Doe":"is here"}}' | ||
155 | }, "Casper.open() used the expected POST settings"); | ||
156 | }); | ||
157 | |||
158 | casper.run(function() { | ||
159 | test.done(); | ||
160 | }); | ||
161 | } | ||
162 | }); | ||
163 | |||
133 | casper.test.begin('open() PUT tests', 2, { | 164 | casper.test.begin('open() PUT tests', 2, { |
134 | setUp: setUp, | 165 | setUp: setUp, |
135 | tearDown: tearDown, | 166 | tearDown: tearDown, | ... | ... |
-
Please register or sign in to post a comment