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

[Backport 2.x] Command with query parameter reports unrecognized parameter in DevTools #3834

Merged
merged 1 commit into from
Apr 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ function getProxyHeaders(req: OpenSearchDashboardsRequest) {
}

function toUrlPath(path: string) {
let urlPath = `/${trimStart(path, '/')}`;
const FAKE_BASE = 'http://localhost';
const urlWithFakeBase = new URL(`${FAKE_BASE}/${trimStart(path, '/')}`);
// Appending pretty here to have OpenSearch do the JSON formatting, as doing
// in JS can lead to data loss (7.0 will get munged into 7, thus losing indication of
// measurement precision)
if (!urlPath.includes('?pretty')) {
urlPath += '?pretty=true';
if (!urlWithFakeBase.searchParams.get('pretty')) {
urlWithFakeBase.searchParams.append('pretty', 'true');
}
const urlPath = urlWithFakeBase.href.replace(urlWithFakeBase.origin, '');
return urlPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ describe('Console Proxy Route', () => {
expect(args.path).toBe('/index/id?pretty=true');
});
});

describe(`contains query parameter`, () => {
it('adds slash to path before sending request', async () => {
await request('GET', '_cat/tasks?v');
const [[args]] = opensearchClient.asCurrentUser.transport.request.mock.calls;
expect(args.path).toBe('/_cat/tasks?v=&pretty=true');
});
});
});
});
});