From 3354d4ad3e2bfde5706649c2ca3725fa51a42477 Mon Sep 17 00:00:00 2001 From: dancode-188 Date: Sun, 28 Dec 2025 02:10:43 +0300 Subject: [PATCH] fix: normalize undefined to null and replace placeholders, fixes #14 #15 Two related issues in variable extraction: 1. extractVariables could return undefined when JSONPath finds nothing, but should return null for consistency with error handling. 2. interpolateVariables kept {{placeholder}} syntax when variables were undefined/null instead of replacing them with string representations. Changes: - Normalize JSONPath undefined results to null - Replace undefined variables with 'undefined' string - Replace null variables with 'null' string This makes variable handling consistent and prevents stale placeholders in interpolated text. --- src/lib/variable-extraction-service.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/variable-extraction-service.ts b/src/lib/variable-extraction-service.ts index 75eafb4..14e37c6 100644 --- a/src/lib/variable-extraction-service.ts +++ b/src/lib/variable-extraction-service.ts @@ -40,7 +40,8 @@ class VariableExtractionService { wrap: false, }); - extracted[extraction.name] = result; + // Normalize undefined to null for consistency + extracted[extraction.name] = result === undefined ? null : result; } catch (error) { console.error(`Failed to extract variable ${extraction.name}:`, error); extracted[extraction.name] = null; @@ -78,10 +79,14 @@ class VariableExtractionService { // Support nested paths like {{user.id}} const value = this.getNestedValue(variables, trimmedName); - - if (value === undefined || value === null) { + + if (value === undefined) { console.warn(`Variable ${trimmedName} not found`); - return match; // Keep original if not found + return 'undefined'; + } + + if (value === null) { + return 'null'; } return String(value);