mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-20 20:58:38 +01:00
fix(#2767): Fix serilization issues of bigint in json body
This commit is contained in:
parent
72c3aaa5ba
commit
e0858d1c99
@ -17,8 +17,6 @@ const Timeline = ({ request, response }) => {
|
||||
});
|
||||
});
|
||||
|
||||
let requestData = safeStringifyJSON(request.data);
|
||||
|
||||
return (
|
||||
<StyledWrapper className="pb-4 w-full">
|
||||
<div>
|
||||
@ -33,9 +31,9 @@ const Timeline = ({ request, response }) => {
|
||||
);
|
||||
})}
|
||||
|
||||
{requestData ? (
|
||||
{request.data ? (
|
||||
<pre className="line request">
|
||||
<span className="arrow">{'>'}</span> data {requestData}
|
||||
<span className="arrow">{'>'}</span> data <pre>{request.data}</pre>
|
||||
</pre>
|
||||
) : null}
|
||||
</div>
|
||||
|
@ -59,14 +59,6 @@ const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEn
|
||||
const contentType = getContentType(request.headers);
|
||||
|
||||
if (contentType.includes('json')) {
|
||||
if (typeof request.data === 'object') {
|
||||
try {
|
||||
let parsed = JSON.stringify(request.data);
|
||||
parsed = _interpolate(parsed);
|
||||
request.data = JSON.parse(parsed);
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
if (typeof request.data === 'string') {
|
||||
if (request.data.length) {
|
||||
request.data = _interpolate(request.data);
|
||||
|
@ -1,7 +1,6 @@
|
||||
const os = require('os');
|
||||
const { get, each, filter, extend, compact } = require('lodash');
|
||||
const decomment = require('decomment');
|
||||
var JSONbig = require('json-bigint');
|
||||
const FormData = require('form-data');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
@ -342,16 +341,10 @@ const prepareRequest = (item, collection) => {
|
||||
if (!contentTypeDefined) {
|
||||
axiosRequest.headers['content-type'] = 'application/json';
|
||||
}
|
||||
let jsonBody;
|
||||
try {
|
||||
jsonBody = decomment(request?.body?.json);
|
||||
axiosRequest.data = decomment(request?.body?.json);
|
||||
} catch (error) {
|
||||
jsonBody = request?.body?.json;
|
||||
}
|
||||
try {
|
||||
axiosRequest.data = JSONbig.parse(jsonBody);
|
||||
} catch (error) {
|
||||
axiosRequest.data = jsonBody;
|
||||
axiosRequest.data = request?.body?.json;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,11 +56,31 @@ class BrunoRequest {
|
||||
this.req.headers[name] = value;
|
||||
}
|
||||
|
||||
getBody() {
|
||||
/**
|
||||
* Get the body of the request
|
||||
*
|
||||
* @param {*} options
|
||||
* @param {boolean} options.raw - If true, return the raw body without parsing it
|
||||
* @returns
|
||||
*/
|
||||
getBody(options = {}) {
|
||||
let headers = this.req.headers;
|
||||
const contentType = headers?.['Content-Type'] || headers?.['content-type'] || '';
|
||||
const hasJSONContentType = contentType.includes('json');
|
||||
|
||||
if (hasJSONContentType && !options.raw) {
|
||||
return JSON.parse(this.req.data);
|
||||
}
|
||||
|
||||
return this.req.data;
|
||||
}
|
||||
|
||||
setBody(data) {
|
||||
if (typeof data === 'object') {
|
||||
this.req.data = JSON.stringify(data);
|
||||
return;
|
||||
}
|
||||
|
||||
this.req.data = data;
|
||||
}
|
||||
|
||||
|
44
packages/bruno-tests/collection/echo/echo bigint.bru
Normal file
44
packages/bruno-tests/collection/echo/echo bigint.bru
Normal file
@ -0,0 +1,44 @@
|
||||
meta {
|
||||
name: echo bigint
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
foo: bar
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: asd
|
||||
password: j
|
||||
}
|
||||
|
||||
auth:bearer {
|
||||
token:
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": 990531470713421825
|
||||
}
|
||||
}
|
||||
|
||||
body:text {
|
||||
{
|
||||
"hello": 990531470713421825
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
bru.setVar("foo", "foo-world-2");
|
||||
}
|
Loading…
Reference in New Issue
Block a user