Skip to content

Commit

Permalink
[Enterprise Search] Prevent double encoding in enterprise_search_requ…
Browse files Browse the repository at this point in the history
…est_handler (#79747)
  • Loading branch information
JasonStoltz authored Oct 7, 2020
1 parent f1905ec commit 718702c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ describe('EnterpriseSearchRequestHandler', () => {
});
});

it('passes request params', async () => {
const requestHandler = enterpriseSearchRequestHandler.createRequest({
path: '/api/example',
});
await makeAPICall(requestHandler, { query: { someQuery: false } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/api/example?someQuery=false'
);
});

it('passes custom params set by the handler, which override request params', async () => {
const requestHandler = enterpriseSearchRequestHandler.createRequest({
path: '/api/example',
Expand All @@ -104,6 +115,17 @@ describe('EnterpriseSearchRequestHandler', () => {
'http://localhost:3002/api/example?someQuery=true'
);
});

it('correctly encodes paths and query string parameters', async () => {
const requestHandler = enterpriseSearchRequestHandler.createRequest({
path: '/api/some example',
});
await makeAPICall(requestHandler, { query: { 'page[current]': 1 } });

EnterpriseSearchAPI.shouldHaveBeenCalledWith(
'http://localhost:3002/api/some%20example?page%5Bcurrent%5D=1'
);
});
});

describe('response passing', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class EnterpriseSearchRequestHandler {
const queryString = !this.isEmptyObj(queryParams)
? `?${querystring.stringify(queryParams)}`
: '';
const url = encodeURI(this.enterpriseSearchUrl + path + queryString);
const url = encodeURI(this.enterpriseSearchUrl + path) + queryString;

// Set up API options
const { method } = request.route;
Expand Down

0 comments on commit 718702c

Please sign in to comment.