Skip to content

Commit

Permalink
Fix getLegendGraphicUrl to not append multiple questionmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
weskamm committed Sep 5, 2018
1 parent 37d59f0 commit d1888ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/MapUtil/MapUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.`);
Expand Down
8 changes: 7 additions & 1 deletion src/MapUtil/MapUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d1888ee

Please sign in to comment.