From 2a251b219a84a377b7eef1b89bc51a9cd5f29825 Mon Sep 17 00:00:00 2001 From: Ganesh Iyer Date: Tue, 9 May 2017 14:55:23 -0400 Subject: [PATCH] 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); } }