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

fixing mangling of floating point numbers by console #23685

Merged
merged 8 commits into from
Oct 19, 2018
2 changes: 1 addition & 1 deletion src/core_plugins/console/public/src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function initializeInput($el, $actionsEl, $copyAsCurlEl, output, openDocu
if (mode === null || mode === 'application/json') {
// assume json - auto pretty
try {
value = utils.expandLiteralStrings(JSON.stringify(JSON.parse(value), null, 2));
value = utils.expandLiteralStrings(value);
}
catch (e) {
// nothing to do here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('Console Proxy Route', () => {
expect(args[0]).to.have.property('path', '/api/console/proxy');
expect(args[0]).to.have.property('method', 'post');
expect(args[0]).to.have.property('query').eql({ method: 'HEAD', path: '/index/type/id' });
expect(args[1]).to.be('/index/type/id');
expect(args[1]).to.be('/index/type/id?pretty');
});

it('sends the returned timeout, rejectUnauthorized, agent, and base headers to Wreck', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Console Proxy Route', () => {
await request('GET', 'http://evil.com/test');
sinon.assert.calledOnce(Wreck.request);
const args = Wreck.request.getCall(0).args;
expect(args[1]).to.be('http://localhost:9200/http://evil.com/test');
expect(args[1]).to.be('http://localhost:9200/http://evil.com/test?pretty');
});
});
describe('is missing', () => {
Expand All @@ -87,14 +87,14 @@ describe('Console Proxy Route', () => {
it('combines well with the base url', async () => {
await request('GET', '/index/type/id');
sinon.assert.calledOnce(Wreck.request);
expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id');
expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id?pretty');
});
});
describe(`doesn't start with a slash`, () => {
it('combines well with the base url', async () => {
await request('GET', 'index/type/id');
sinon.assert.calledOnce(Wreck.request);
expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id');
expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id?pretty');
});
});
});
Expand Down
11 changes: 10 additions & 1 deletion src/core_plugins/console/server/proxy_route.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ import Wreck from 'wreck';
import { trimLeft, trimRight } from 'lodash';

function resolveUri(base, path) {
return `${trimRight(base, '/')}/${trimLeft(path, '/')}`;
let pathToUse = `${trimRight(base, '/')}/${trimLeft(path, '/')}`;
const questionMarkIndex = pathToUse.indexOf('?');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can use String.prototype.includes now, so no need for indexOf checks and extra variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work in IE11 though (we've had bugs related to that).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd... it should be in the babel polyfill we use. Anyway, something I can sort out separately from this PR.

// no query string in pathToUse, append '?pretty'
if (questionMarkIndex === -1) {
pathToUse = `${pathToUse}?pretty`;
} else {
// pathToUse has query string, append '&pretty'
pathToUse = `${pathToUse}&pretty`;
}
return pathToUse;
}

function extendCommaList(obj, property, value) {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/apps/console/_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default function ({ getService, getPageObjects }) {
});
});

it('default request response should include `"timed_out": false`', async function () {
const expectedResponseContains = '"timed_out": false,';
it('default request response should include `"timed_out" : false`', async function () {
const expectedResponseContains = '"timed_out" : false,';
await PageObjects.console.clickPlay();
await retry.try(async function () {
const actualResponse = await PageObjects.console.getResponse();
Expand Down