diff --git a/src/ogc-api/endpoint.spec.ts b/src/ogc-api/endpoint.spec.ts index e4af220..826279b 100644 --- a/src/ogc-api/endpoint.spec.ts +++ b/src/ogc-api/endpoint.spec.ts @@ -2166,4 +2166,45 @@ The document at http://local/nonexisting?f=json could not be fetched.` }); }); }); + describe('endpoint with query params', () => { + describe('on collections path', () => { + beforeEach(() => { + endpoint = new OgcApiEndpoint( + 'http://local/sample-data/collections?foo=bar' + ); + }); + it('correctly parses endpoint info and collections', async () => { + await expect(endpoint.info).resolves.toEqual({ + title: 'OS Open Zoomstack', + description: + 'OS Open Zoomstack is a comprehensive vector basemap showing coverage of Great Britain at a national level, right down to street-level detail.', + attribution: + 'Contains OS data © Crown copyright and database right 2021.', + }); + await expect(endpoint.featureCollections).resolves.toEqual([ + 'airports', + 'boundaries', + 'contours', + 'district_buildings', + 'etl', + 'foreshore', + 'greenspace', + 'land', + 'local_buildings', + 'names', + 'national_parks', + 'rail', + 'railway_stations', + 'roads_local', + 'roads_national', + 'roads_regional', + 'sites', + 'surfacewater', + 'urban_areas', + 'waterlines', + 'woodland', + ]); + }); + }); + }); }); diff --git a/src/ogc-api/link-utils.ts b/src/ogc-api/link-utils.ts index 80d3b1a..5ead8a7 100644 --- a/src/ogc-api/link-utils.ts +++ b/src/ogc-api/link-utils.ts @@ -69,7 +69,11 @@ export function fetchCollectionRoot( } // if there is a collections array, we expect the parent path to end with slash if ('collections' in doc) { - parentUrl = `${parentUrl}/`; + const urlObj = new URL(parentUrl); + if (!urlObj.pathname.endsWith('/')) { + urlObj.pathname = `${urlObj.pathname}/`; + } + parentUrl = urlObj.toString(); } return fetchCollectionRoot(parentUrl); });