Allow extra qualifications when matching json content-type

This commit is contained in:
slackersoft 2014-06-12 13:33:48 -07:00
parent d893394765
commit 54864a45d3
2 changed files with 18 additions and 1 deletions

View File

@ -117,7 +117,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
var defaults = [ var defaults = [
{ {
test: function(xhr) { test: function(xhr) {
return xhr.contentType() === 'application/json'; return /^application\/json/.test(xhr.contentType());
}, },
parse: function jsonParser(paramString) { parse: function jsonParser(paramString) {
return JSON.parse(paramString); return JSON.parse(paramString);

View File

@ -145,6 +145,23 @@ describe("FakeXMLHttpRequest", function() {
expect(xhr.data()).toEqual(data); expect(xhr.data()).toEqual(data);
}); });
it("should parse json even if there are further qualifiers", function() {
var data = {
foo: 'bar',
baz: ['q', 'u', 'u', 'x'],
nested: {
object: {
with: 'stuff'
}
}
};
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.send(JSON.stringify(data));
expect(xhr.data()).toEqual(data);
});
it("should be able to use a custom parser", function() { it("should be able to use a custom parser", function() {
xhr.send('custom_format'); xhr.send('custom_format');
var custom = { var custom = {