Skip to content

Commit

Permalink
fix(charts): 404 error when retrieving a chart with spaces in the name (
Browse files Browse the repository at this point in the history
  • Loading branch information
ghusse committed Oct 11, 2023
1 parent 85b8c40 commit 29b47db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/agent/src/routes/base-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export default abstract class BaseRoute {
abstract setupRoutes(router: Router): void;

protected escapeUrlSlug(name: string): string {
return name.replace(/([+?*])/g, '\\$1');
return encodeURI(name).replace(/([+?*])/g, '\\$1');
}
}
19 changes: 19 additions & 0 deletions packages/agent/test/routes/access/api-chart-datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,24 @@ describe('DataSourceApiChartRoute', () => {

expect(router.get).toHaveBeenCalledWith('/_charts/myChart\\+\\*\\?', expect.any(Function));
});

it('should register routes with encoded names', () => {
const options = factories.forestAdminHttpDriverOptions.build();
const router = factories.router.mockAllMethods().build();
const services = factories.forestAdminHttpDriverServices.build();
const dataSource = factories.dataSource.build({
schema: { charts: ['my awesome chart'] },
renderChart: jest.fn().mockResolvedValue({ countCurrent: 12 }),
});

const route = new DataSourceApiChartRoute(services, options, dataSource, 'my awesome chart');

route.setupRoutes(router);

expect(router.get).toHaveBeenCalledWith(
'/_charts/my%20awesome%20chart',
expect.any(Function),
);
});
});
});

0 comments on commit 29b47db

Please sign in to comment.