Avoid using eval when JSON.parse is available.

This commit is contained in:
Antoine Vandecreme 2015-07-30 16:21:59 -04:00
parent 1c17374de1
commit 4bb80067f7
2 changed files with 19 additions and 2 deletions

View File

@ -2176,6 +2176,24 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
return $.parseXml( string ); return $.parseXml( string );
}, },
/**
* Parses a JSON string into a Javascript object.
* @function
* @param {String} string
* @returns {Object}
*/
parseJSON: function(string) {
if (window.JSON && window.JSON.parse) {
$.parseJSON = window.JSON.parse;
} else {
// Should only be used by IE8 in non standards mode
$.parseJSON = function(string) {
/*jshint evil:true*/
return eval('(' + string + ')');
};
}
return $.parseJSON(string);
},
/** /**
* Reports whether the image format is supported for tiling in this * Reports whether the image format is supported for tiling in this

View File

@ -613,8 +613,7 @@ function processResponse( xhr ){
data = xhr.responseText; data = xhr.responseText;
} }
}else if( responseText.match(/\s*[\{\[].*/) ){ }else if( responseText.match(/\s*[\{\[].*/) ){
/*jshint evil:true*/ data = $.parseJSON(responseText);
data = eval( '('+responseText+')' );
}else{ }else{
data = responseText; data = responseText;
} }