mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-07 08:34:15 +01:00
fix: decomment not working in json body (#1819)
Request body json was not decommented if json parsing fails, which would happen if variables are not quoted. Fixes usebruno#888
This commit is contained in:
parent
a0df5138b3
commit
9c11e27d1c
@ -76,10 +76,11 @@ const prepareRequest = (request, collectionRoot) => {
|
||||
if (!contentTypeDefined) {
|
||||
axiosRequest.headers['content-type'] = 'application/json';
|
||||
}
|
||||
const jsonBody = decomment(request.body.json);
|
||||
try {
|
||||
axiosRequest.data = JSONbig.parse(decomment(request.body.json));
|
||||
axiosRequest.data = JSONbig.parse(jsonBody);
|
||||
} catch (ex) {
|
||||
axiosRequest.data = request.body.json;
|
||||
axiosRequest.data = jsonBody;
|
||||
}
|
||||
}
|
||||
|
||||
|
21
packages/bruno-cli/tests/runner/prepare-request.spec.js
Normal file
21
packages/bruno-cli/tests/runner/prepare-request.spec.js
Normal file
@ -0,0 +1,21 @@
|
||||
const { describe, it, expect } = require('@jest/globals');
|
||||
|
||||
const prepareRequest = require('../../src/runner/prepare-request');
|
||||
|
||||
describe('prepare-request: prepareRequest', () => {
|
||||
describe('Decomments request body', () => {
|
||||
it('If request body is valid JSON', async () => {
|
||||
const body = { mode: 'json', json: '{\n"test": "{{someVar}}" // comment\n}' };
|
||||
const expected = { test: '{{someVar}}' };
|
||||
const result = prepareRequest({ body });
|
||||
expect(result.data).toEqual(expected);
|
||||
});
|
||||
|
||||
it('If request body is not valid JSON', async () => {
|
||||
const body = { mode: 'json', json: '{\n"test": {{someVar}} // comment\n}' };
|
||||
const expected = '{\n"test": {{someVar}} \n}';
|
||||
const result = prepareRequest({ body });
|
||||
expect(result.data).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
@ -172,10 +172,11 @@ const prepareRequest = (request, collectionRoot, collectionPath) => {
|
||||
if (!contentTypeDefined) {
|
||||
axiosRequest.headers['content-type'] = 'application/json';
|
||||
}
|
||||
const body = decomment(request.body.json);
|
||||
try {
|
||||
axiosRequest.data = JSONbig.parse(decomment(request.body.json));
|
||||
axiosRequest.data = JSONbig.parse(body);
|
||||
} catch (ex) {
|
||||
axiosRequest.data = request.body.json;
|
||||
axiosRequest.data = body;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
const { describe, it, expect } = require('@jest/globals');
|
||||
|
||||
const prepareRequest = require('../../src/ipc/network/prepare-request');
|
||||
|
||||
describe('prepare-request: prepareRequest', () => {
|
||||
describe('Decomments request body', () => {
|
||||
it('If request body is valid JSON', async () => {
|
||||
const body = { mode: 'json', json: '{\n"test": "{{someVar}}" // comment\n}' };
|
||||
const expected = { test: '{{someVar}}' };
|
||||
const result = prepareRequest({ body });
|
||||
expect(result.data).toEqual(expected);
|
||||
});
|
||||
|
||||
it('If request body is not valid JSON', async () => {
|
||||
const body = { mode: 'json', json: '{\n"test": {{someVar}} // comment\n}' };
|
||||
const expected = '{\n"test": {{someVar}} \n}';
|
||||
const result = prepareRequest({ body });
|
||||
expect(result.data).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user