Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URL manipulation in link-utils #86

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/ogc-api/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});
});
});
});
6 changes: 5 additions & 1 deletion src/ogc-api/link-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Loading