mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Merge pull request #696 from avandecreme/master
Avoid using eval when JSON.parse is available.
This commit is contained in:
commit
bc6759e7fb
@ -2208,6 +2208,24 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
||||
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
|
||||
|
@ -613,8 +613,7 @@ function processResponse( xhr ){
|
||||
data = xhr.responseText;
|
||||
}
|
||||
}else if( responseText.match(/\s*[\{\[].*/) ){
|
||||
/*jshint evil:true*/
|
||||
data = eval( '('+responseText+')' );
|
||||
data = $.parseJSON(responseText);
|
||||
}else{
|
||||
data = responseText;
|
||||
}
|
||||
|
@ -1996,8 +1996,7 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
|
||||
if ( tileSource.match( /\s*<.*/ ) ) {
|
||||
tileSource = $.parseXml( tileSource );
|
||||
} else if ( tileSource.match( /\s*[\{\[].*/ ) ) {
|
||||
/*jshint evil:true*/
|
||||
tileSource = eval( '(' + tileSource + ')' );
|
||||
tileSource = $.parseJSON(tileSource);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,18 @@
|
||||
var viewer = null;
|
||||
|
||||
// ----------
|
||||
var testOpen = function(name) {
|
||||
var testOpenUrl = function(relativeUrl) {
|
||||
testOpen('/test/data/' + relativeUrl);
|
||||
};
|
||||
|
||||
var testOpen = function(tileSource) {
|
||||
$(document).ready(function() {
|
||||
var timeWatcher = Util.timeWatcher(7000);
|
||||
|
||||
viewer = OpenSeadragon({
|
||||
id: 'example',
|
||||
prefixUrl: '/build/openseadragon/images/',
|
||||
tileSources: '/test/data/' + name
|
||||
tileSources: tileSource
|
||||
});
|
||||
|
||||
ok(viewer, 'Viewer exists');
|
||||
@ -52,62 +56,90 @@
|
||||
|
||||
// ----------
|
||||
asyncTest('DZI', function() {
|
||||
testOpen('testpattern.dzi');
|
||||
testOpenUrl('testpattern.dzi');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('DZI JSONp', function() {
|
||||
testOpen('testpattern.js');
|
||||
testOpenUrl('testpattern.js');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('DZI XML', function() {
|
||||
testOpen('testpattern.xml');
|
||||
testOpenUrl('testpattern.xml');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('DZI XML with query parameter', function() {
|
||||
testOpen('testpattern.xml?param=value');
|
||||
testOpenUrl('testpattern.xml?param=value');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF 1.0 JSON', function() {
|
||||
testOpen('iiif_1_0_files/info.json');
|
||||
testOpenUrl('iiif_1_0_files/info.json');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF 1.0 XML', function() {
|
||||
testOpen('iiif_1_0_files/info.xml');
|
||||
testOpenUrl('iiif_1_0_files/info.xml');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF 1.1 JSON', function() {
|
||||
testOpen('iiif_1_1_tiled/info.json');
|
||||
testOpenUrl('iiif_1_1_tiled/info.json');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF No Tiles, Less than 256', function() {
|
||||
testOpen('iiif_1_1_no_tiles_255/info.json');
|
||||
testOpenUrl('iiif_1_1_no_tiles_255/info.json');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF No Tiles, Bet. 256 and 512', function() {
|
||||
testOpen('iiif_1_1_no_tiles_384/info.json');
|
||||
testOpenUrl('iiif_1_1_no_tiles_384/info.json');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF No Tiles, Bet. 512 and 1024', function() {
|
||||
testOpen('iiif_1_1_no_tiles_768/info.json');
|
||||
testOpenUrl('iiif_1_1_no_tiles_768/info.json');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF No Tiles, Larger than 1024', function() {
|
||||
testOpen('iiif_1_1_no_tiles_1048/info.json');
|
||||
testOpenUrl('iiif_1_1_no_tiles_1048/info.json');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF 2.0 JSON', function() {
|
||||
testOpen('iiif_2_0_tiled/info.json');
|
||||
testOpenUrl('iiif_2_0_tiled/info.json');
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest('IIIF 2.0 JSON String', function() {
|
||||
testOpen(
|
||||
'{' +
|
||||
' "@context": "http://iiif.io/api/image/2/context.json",' +
|
||||
' "@id": "http://localhost:8000/test/data/iiif_2_0_tiled",' +
|
||||
' "protocol": "http://iiif.io/api/image",' +
|
||||
' "height": 1024,' +
|
||||
' "width": 775,' +
|
||||
' "tiles" : [{"width":256, "scaleFactors":[1,2,4,8]}],' +
|
||||
' "profile": ["http://iiif.io/api/image/2/level1.json",' +
|
||||
' {' +
|
||||
' "qualities": [' +
|
||||
' "native",' +
|
||||
' "bitonal",' +
|
||||
' "grey",' +
|
||||
' "color"' +
|
||||
' ],' +
|
||||
' "formats": [' +
|
||||
' "jpg",' +
|
||||
' "png",' +
|
||||
' "gif"' +
|
||||
' ]' +
|
||||
' }' +
|
||||
' ]' +
|
||||
'}');
|
||||
});
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user