Skip to content

Commit

Permalink
Makes sure all converters keys are lowercased before any conversion i…
Browse files Browse the repository at this point in the history
…s taking place: dataTypes' names are now truly case insensitive. Unit test edited.
  • Loading branch information
jaubourg committed Jan 31, 2011
1 parent 485fa0c commit 7c9a5e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/ajax.js
Expand Up @@ -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
Expand All @@ -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 ];
Expand Down
8 changes: 4 additions & 4 deletions test/unit/ajax.js
Expand Up @@ -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" );
Expand All @@ -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 (*)" );
Expand Down

0 comments on commit 7c9a5e6

Please sign in to comment.