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

Commit

Permalink
Fix body and bodyRaw helpers for empty string paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume committed Feb 23, 2022
1 parent 1b91007 commit b16c1d5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/libs/templating-helpers/request-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ export const RequestHelpers = function (
) {
return {
// get json property from body
body: function (path: string, defaultValue: string, stringify: boolean) {
body: function (
path: string | null,
defaultValue: string,
stringify: boolean
) {
// no path provided
if (typeof path === 'object') {
path = '';
path = null;
}

// no default value provided
Expand All @@ -26,7 +30,7 @@ export const RequestHelpers = function (
}

// if no path has been provided we want the full raw body as is
if (path == null) {
if (path == null || path === '') {
return new SafeString(request.body);
}

Expand All @@ -51,7 +55,7 @@ export const RequestHelpers = function (
},
// get the raw json property from body to use with each for example
bodyRaw: function (...args: any[]) {
let path = '';
let path: string | null = null;
let defaultValue = '';
const parameters = args.slice(0, -1); // remove last item (handlebars options argument)

Expand All @@ -64,7 +68,7 @@ export const RequestHelpers = function (

if (request.parsedBody) {
// if no path has been provided we want the full raw body as is
if (path == null) {
if (path == null || path === '') {
return request.parsedBody;
}

Expand Down

0 comments on commit b16c1d5

Please sign in to comment.