Skip to content

Commit

Permalink
Fix command with query parameter rejected in DevTools (#3813) (#3834)
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
(cherry picked from commit e12ae0b)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 8693f5d commit 48c3920
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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');
});
});
});
});
});

0 comments on commit 48c3920

Please sign in to comment.