From 7c9a5e6016c2fcd38872367a891e5b3887d3df53 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Mon, 31 Jan 2011 17:39:54 +0100 Subject: [PATCH] Makes sure all converters keys are lowercased before any conversion is taking place: dataTypes' names are now truly case insensitive. Unit test edited. --- src/ajax.js | 13 ++++++++++++- test/unit/ajax.js | 8 ++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 11eacee71..39abe9059 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -842,8 +842,9 @@ function ajaxConvert( s, response ) { } var dataTypes = s.dataTypes, - converters = s.converters, + converters = {}, i, + key, length = dataTypes.length, tmp, // Current and previous dataTypes @@ -860,6 +861,16 @@ function ajaxConvert( s, response ) { // For each dataType in the chain for( i = 1; i < length; i++ ) { + // Create converters map + // with lowercased keys + if ( i === 1 ) { + for( key in s.converters ) { + if( typeof key === "string" ) { + converters[ key.toLowerCase() ] = s.converters[ key ]; + } + } + } + // Get the dataTypes prev = current; current = dataTypes[ i ]; diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 716ed9c97..9d088f3c7 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2077,12 +2077,12 @@ test("jQuery.ajax - transitive conversions", function() { jQuery.ajax( url("data/json.php") , { converters: { - "json myjson": function( data ) { + "json myJson": function( data ) { ok( true , "converter called" ); return data; } }, - dataType: "myjson", + dataType: "myJson", success: function() { ok( true , "Transitive conversion worked" ); strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" ); @@ -2092,13 +2092,13 @@ test("jQuery.ajax - transitive conversions", function() { jQuery.ajax( url("data/json.php") , { converters: { - "json myjson": function( data ) { + "json myJson": function( data ) { ok( true , "converter called (*)" ); return data; } }, contents: false, /* headers are wrong so we ignore them */ - dataType: "* myjson", + dataType: "* myJson", success: function() { ok( true , "Transitive conversion worked (*)" ); strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" ); -- 2.39.5