Skip to content

Commit

Permalink
better handle root path lookup if query params present
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Apr 29, 2024
1 parent 46dce5e commit 40b8cca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/ogc-api/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1810,4 +1810,23 @@ The document at http://local/nonexisting?f=json could not be fetched.`
});
});
});

describe('url with trailing ?', () => {
beforeEach(() => {
endpoint = new OgcApiEndpoint(
'http://local/sample-data/collections/airports/items?'
);
});
describe('#info', () => {
it('returns endpoint info', 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.',
});
});
});
});
});
8 changes: 8 additions & 0 deletions src/ogc-api/link-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ describe('link utils', () => {
'http://example.com/foo'
);
});
it('should keep query params', () => {
expect(getParentPath('http://example.com/foo/bar?aa=bb')).toBe(
'http://example.com/foo?aa=bb'
);
expect(getParentPath('http://example.com/foo/bar?')).toBe(
'http://example.com/foo?'
);
});
});
});
4 changes: 3 additions & 1 deletion src/ogc-api/link-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export function fetchRoot(url: string): Promise<OgcApiDocument> {
}
// 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);
urlObj.pathname = `${urlObj.pathname}/`;
parentUrl = urlObj.toString();
}
return fetchRoot(parentUrl);
}
Expand Down

0 comments on commit 40b8cca

Please sign in to comment.