Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Fix command with query parameter rejected in DevTools (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#3813)

Signed-off-by: Hailong Cui <ihailong@amazon.com>
Signed-off-by: David Sinclair <david@sinclair.tech>
  • Loading branch information
Hailong-am authored and sikhote committed Apr 24, 2023
1 parent 8522274 commit 8dfb44e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG] Fix suggestion list cutoff issue ([#2607](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2607))
- [TSVB] Fixes undefined serial diff aggregation documentation link ([#3503](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3503))
- [Console] Fix dev tool console autocomplete not loading issue ([#3775](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3775))
- [Console] Fix dev tool console run command with query parameter error ([#3813](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3813))

### 🚞 Infrastructure

Expand Down
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 8dfb44e

Please sign in to comment.