From d1888ee2698e914c9c8418eb4d6e09c5aa3d03f5 Mon Sep 17 00:00:00 2001 From: Johannes Weskamm Date: Wed, 5 Sep 2018 15:17:10 +0200 Subject: [PATCH] Fix getLegendGraphicUrl to not append multiple questionmarks --- src/MapUtil/MapUtil.js | 3 ++- src/MapUtil/MapUtil.spec.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/MapUtil/MapUtil.js b/src/MapUtil/MapUtil.js index 372550bf2..807dbc10a 100644 --- a/src/MapUtil/MapUtil.js +++ b/src/MapUtil/MapUtil.js @@ -295,6 +295,7 @@ export class MapUtil { * Get the getlegendGraphic url of a layer. Designed for geoserver. * Currently supported Sources: * - ol.source.TileWms (with url configured) + * - ol.source.ImageWms (with url configured) * * @param {ol.layer.Layer} layer The layer that you want to have a legendUrlfor. * @return {String|undefined} The getLegendGraphicUrl. @@ -330,7 +331,7 @@ export class MapUtil { const queryString = UrlUtil.objectToRequestString( Object.assign(params, extraParams)); - return `${url}?${queryString}`; + return url.endsWith('?') ? `${url}${queryString}` : `${url}?${queryString}`; } else { Logger.warn(`Source of "${layer.get('name')}" is currently not supported ` + `by MapUtil.getLegendGraphicUrl.`); diff --git a/src/MapUtil/MapUtil.spec.js b/src/MapUtil/MapUtil.spec.js index 470afaf1f..7e332b9c1 100644 --- a/src/MapUtil/MapUtil.spec.js +++ b/src/MapUtil/MapUtil.spec.js @@ -474,7 +474,7 @@ describe('MapUtil', () => { layer1 = new OlLayerTile({ name: 'OSM-WMS', source: new OlSourceTileWMS({ - url: 'https://ows.terrestris.de/osm-gray/service', + url: 'https://ows.terrestris.de/osm-gray/service?', params: {'LAYERS': 'OSM-WMS', 'TILED': true}, serverType: 'geoserver' }) @@ -551,6 +551,12 @@ describe('MapUtil', () => { }); }); + it('Does not append multiple questionmarks in URL', () => { + const legendUrl = MapUtil.getLegendGraphicUrl(layer1); + expect(legendUrl).toEqual(expect.stringContaining('?')); + expect(legendUrl).toEqual(expect.not.stringContaining('??')); + }); + it('accepts extraParams for the request', () => { const extraParams = { HEIGHT: 10,