From 2a251b219a84a377b7eef1b89bc51a9cd5f29825 Mon Sep 17 00:00:00 2001 From: Ganesh Iyer Date: Tue, 9 May 2017 14:55:23 -0400 Subject: [PATCH 1/2] added fix for supporting weird filenames that look like JSONs --- src/viewer.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/viewer.js b/src/viewer.js index ec4c8242..f59bf8a7 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2113,6 +2113,20 @@ function _getSafeElemSize (oElement) { ); } + +/* + * @function + * @private + */ +function _isJSON(str){ + try{ + JSON.parse(str); + } catch (e) { + return false; + } + return true; +} + /** * @function * @private @@ -2127,7 +2141,7 @@ function getTileSourceImplementation( viewer, tileSource, imgOptions, successCal if ( tileSource.match( /^\s*<.*>\s*$/ ) ) { tileSource = $.parseXml( tileSource ); //json should start with "{" or "[" and end with "}" or "]" - } else if ( tileSource.match(/^\s*[\{\[].*[\}\]]\s*$/ ) ) { + } else if ( _isJSON(tileSource) ) { tileSource = $.parseJSON(tileSource); } } From ce1360f5cb65e4c194183c96c7ae1c2221604ba7 Mon Sep 17 00:00:00 2001 From: Ganesh Iyer Date: Wed, 10 May 2017 17:51:59 -0400 Subject: [PATCH 2/2] using try/catch $.parseJSON to check for JSONs --- src/tilesource.js | 6 +++++- src/viewer.js | 22 +++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/tilesource.js b/src/tilesource.js index 135053de..431b37d3 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -629,7 +629,11 @@ function processResponse( xhr ){ data = xhr.responseText; } }else if( responseText.match(/\s*[\{\[].*/) ){ - data = $.parseJSON(responseText); + try{ + data = $.parseJSON(responseText); + } catch(e){ + data = responseText; + } }else{ data = responseText; } diff --git a/src/viewer.js b/src/viewer.js index f59bf8a7..91317cd3 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2114,19 +2114,6 @@ function _getSafeElemSize (oElement) { } -/* - * @function - * @private - */ -function _isJSON(str){ - try{ - JSON.parse(str); - } catch (e) { - return false; - } - return true; -} - /** * @function * @private @@ -2141,8 +2128,13 @@ function getTileSourceImplementation( viewer, tileSource, imgOptions, successCal if ( tileSource.match( /^\s*<.*>\s*$/ ) ) { tileSource = $.parseXml( tileSource ); //json should start with "{" or "[" and end with "}" or "]" - } else if ( _isJSON(tileSource) ) { - tileSource = $.parseJSON(tileSource); + } else if ( tileSource.match(/^\s*[\{\[].*[\}\]]\s*$/ ) ) { + try { + var tileSourceJ = $.parseJSON(tileSource); + tileSource = tileSourceJ; + } catch (e) { + //tileSource = tileSource; + } } }