From d3e23a2986698166bed0989def586083c5136891 Mon Sep 17 00:00:00 2001 From: Gaetano Guerriero Date: Wed, 3 Feb 2016 00:27:14 +0100 Subject: [PATCH] fixed dzitilesource guessing of tilesUrl. Now the regex guessing the root url of tiles works also if the data url (the url from which information about the tile was downloaded) does not ends with .dzi, .xml or .js. --- src/dzitilesource.js | 3 ++- test/modules/dztilesource.js | 38 ++++++++++++++++++++++++++++++++++++ test/test.html | 3 ++- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/modules/dztilesource.js diff --git a/src/dzitilesource.js b/src/dzitilesource.js index 99dd92d1..5d00980f 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -139,7 +139,8 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, /** @lends OpenSead } if (url && !options.tilesUrl) { - options.tilesUrl = url.replace(/([^\/]+)\.(dzi|xml|js)(\?.*|$)/, '$1_files/'); + options.tilesUrl = url.replace( + /([^\/]+?)(\.(dzi|xml|js))?\/?(\?.*)?$/, '$1_files/'); if (url.search(/\.(dzi|xml|js)\?/) != -1) { options.queryParams = url.match(/\?.*/); diff --git a/test/modules/dztilesource.js b/test/modules/dztilesource.js new file mode 100644 index 00000000..fe4677a0 --- /dev/null +++ b/test/modules/dztilesource.js @@ -0,0 +1,38 @@ + +/*global module:true, test:true, equal:true, OpenSeadragon:true*/ + +(function() { + + module('DziTileSource', { + setup: function() { + testLog.reset(); + } + }); + + function testImplicitTilesUrl(dziUrl, expected, msg) { + var source = new OpenSeadragon.DziTileSource(); + var options = source.configure({ + Image: {Size: {Width:0, Height: 0}} + }, dziUrl); + equal(options.tilesUrl, expected, msg); + } + + test('test implicit tilesUrl guessed from dzi url', function() { + testImplicitTilesUrl( + '/path/my.dzi', '/path/my_files/', + 'dzi extension should be stripped'); + testImplicitTilesUrl( + '/path/my', '/path/my_files/', + 'no extension should still produce _files path'); + testImplicitTilesUrl( + '/my/', '/my_files/', + 'no extension with trailing slash should preserve slash'); + testImplicitTilesUrl( + 'my.xml', 'my_files/', + 'relative link should stay the same'); + testImplicitTilesUrl( + '/p/foo.dzi?a=1&b=2', '/p/foo_files/', + 'querystring in dzi url should be ignored'); + }); + +}()); diff --git a/test/test.html b/test/test.html index d50e53eb..4a8b311f 100644 --- a/test/test.html +++ b/test/test.html @@ -1,4 +1,4 @@ - + @@ -37,6 +37,7 @@ +