Skip to content

Commit 53ec23b

Browse files
committed
fix: updated the branch
2 parents 5d3ba9d + d9614f2 commit 53ec23b

File tree

1 file changed

+30
-41
lines changed

1 file changed

+30
-41
lines changed

src/modules/workspace/services/collection.service.ts

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ export class CollectionService {
11521152
return text.replace(
11531153
/(\{\{.*?\}\})|([^{}]+)/g,
11541154
(match, insideBraces, outside) => {
1155-
if (insideBraces) return insideBraces;
1155+
if (insideBraces) return insideBraces; // skip {{ }}
11561156
let updated = outside;
11571157
for (const variable of generatedVariables) {
11581158
if (updated === variable.value) {
@@ -1184,49 +1184,38 @@ export class CollectionService {
11841184
}));
11851185
};
11861186

1187-
// Main recursive update
1188-
const replaceValues = (obj: any): any => {
1189-
if (!obj || typeof obj !== "object") {
1190-
return typeof obj === "string" ? replaceOutsideBraces(obj) : obj;
1187+
const newRequest: any = { ...requestItem };
1188+
// url
1189+
if (typeof newRequest.url === "string") {
1190+
newRequest.url = replaceOutsideBraces(newRequest.url);
1191+
}
1192+
// headers
1193+
if (Array.isArray(newRequest.headers)) {
1194+
newRequest.headers = updateKeyValueArray(newRequest.headers);
1195+
}
1196+
// queryParams
1197+
if (Array.isArray(newRequest.queryParams)) {
1198+
newRequest.queryParams = updateKeyValueArray(newRequest.queryParams);
1199+
}
1200+
// body
1201+
if (typeof newRequest.body === "object" && newRequest.body !== null) {
1202+
const updatedBody = { ...newRequest.body };
1203+
if (typeof updatedBody.raw === "string") {
1204+
updatedBody.raw = replaceOutsideBraces(updatedBody.raw);
11911205
}
1192-
const newObj: any = Array.isArray(obj) ? [] : {};
1193-
for (const [key, value] of Object.entries(obj)) {
1194-
if (key === "url" && typeof value === "string") {
1195-
newObj[key] = replaceOutsideBraces(value);
1196-
} else if (key === "headers" && Array.isArray(value)) {
1197-
newObj[key] = updateKeyValueArray(value);
1198-
} else if (key === "queryParams" && Array.isArray(value)) {
1199-
newObj[key] = updateKeyValueArray(value);
1200-
} else if (
1201-
key === "body" &&
1202-
typeof value === "object" &&
1203-
value !== null
1204-
) {
1205-
const updatedBody = { ...(value as RequestBodyDto) };
1206-
if (typeof updatedBody.raw === "string") {
1207-
updatedBody.raw = replaceOutsideBraces(updatedBody.raw);
1208-
}
1209-
if (Array.isArray(updatedBody.urlencoded)) {
1210-
updatedBody.urlencoded = updateKeyValueArray(
1211-
updatedBody.urlencoded,
1212-
);
1213-
}
1214-
if (
1215-
updatedBody.formdata &&
1216-
typeof updatedBody.formdata === "object"
1217-
) {
1218-
if (Array.isArray(updatedBody.formdata.text)) {
1219-
updatedBody.formdata.text = updateKeyValueArray(
1220-
updatedBody.formdata.text,
1221-
);
1222-
}
1223-
}
1224-
newObj[key] = updatedBody;
1206+
if (Array.isArray(updatedBody.urlencoded)) {
1207+
updatedBody.urlencoded = updateKeyValueArray(updatedBody.urlencoded);
1208+
}
1209+
if (updatedBody.formdata && typeof updatedBody.formdata === "object") {
1210+
if (Array.isArray(updatedBody.formdata.text)) {
1211+
updatedBody.formdata.text = updateKeyValueArray(
1212+
updatedBody.formdata.text,
1213+
);
12251214
}
12261215
}
1227-
return newObj;
1228-
};
1229-
return replaceValues(requestItem);
1216+
newRequest.body = updatedBody;
1217+
}
1218+
return newRequest;
12301219
}
12311220

12321221
public async insertGeneratedVariables(

0 commit comments

Comments
 (0)