fix unwanted generation of additional _dotenv_ variables

This commit is contained in:
2026-06-30 12:24:10 +02:00
parent 2727ec67e3
commit f531310718
+17 -5
View File
@@ -92,6 +92,15 @@ function sanitizeVarName(value) {
.replace(/^([0-9])/, '_$1') || 'value'; .replace(/^([0-9])/, '_$1') || 'value';
} }
function parsePlaceholderContent(content) {
const trimmed = String(content).trim();
const dotenvMatch = trimmed.match(/^\$dotenv\s+(.+)$/i);
if (dotenvMatch) {
return { name: dotenvMatch[1].trim(), isDotenv: true };
}
return { name: trimmed, isDotenv: false };
}
function collectPlaceholders(value) { function collectPlaceholders(value) {
if (typeof value !== 'string') { if (typeof value !== 'string') {
return []; return [];
@@ -100,7 +109,7 @@ function collectPlaceholders(value) {
const regex = /\{\{([^{}]+)\}\}/g; const regex = /\{\{([^{}]+)\}\}/g;
let match; let match;
while ((match = regex.exec(value)) !== null) { while ((match = regex.exec(value)) !== null) {
placeholders.push(match[1]); placeholders.push(parsePlaceholderContent(match[1]).name);
} }
return placeholders; return placeholders;
} }
@@ -342,10 +351,13 @@ function buildRequestContent(request, requestName, requestConfig = {}, dotenvVar
if (typeof value !== 'string') { if (typeof value !== 'string') {
return value; return value;
} }
return value.replace(/\{\{([^{}]+)\}\}/g, (match, name) => { return value.replace(/\{\{([^{}]+)\}\}/g, (match, inner) => {
const normalized = String(name).trim(); const placeholder = parsePlaceholderContent(inner);
if (normalized && dotenvVariables.has(normalized)) { if (placeholder.isDotenv) {
return `{{$dotenv ${normalized}}}`; return match;
}
if (placeholder.name && dotenvVariables.has(placeholder.name)) {
return `{{$dotenv ${placeholder.name}}}`;
} }
return match; return match;
}); });