From 7893746582e31747fc17535cf5f9a327ece68812 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Wed, 26 Aug 2026 13:05:24 -0700 Subject: [PATCH] Implement $[&name] for environment-variable access The env-var branch in Tag::getVariable was dead code - it checked for "%", but that sigil was already claimed by the keyword-lookup branch earlier in the same if/else chain, so it could never be reached. Switched to "&" (unused by any other sigil) per explicit user decision. Also fixed a real crash risk while making this reachable: getenv() returns NULL for an unset variable, and MString's const char* constructor calls strlen() unconditionally - now throws a clean "environment variable is not set." error instead. Verified via real jet-2.0 runs: a set variable reads and applies modifiers (;toupper) correctly, an unset one throws cleanly rather than crashing. Full regression suite and 30/30 compile check still pass. --- Tag.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Tag.cpp b/Tag.cpp index 9424198..e0ca433 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -471,16 +471,13 @@ namespace jet { throw coreutils::Exception("session variable requested but no session is active (missing sessiondir keyword, or cgi mode is off)."); coreutils::MString sessionValue = (*global.sessionFile)[name]; return processModifier(sessionValue, modifier); - } else if(variable.ifNext("%")) { - // NOTE: unreachable - '%' is already claimed by the keyword-lookup branch - // above (variable.ifNext("%") at the top of this chain), so this branch - // can never be entered. This looks like a copy-paste where the intended - // sigil character for environment-variable access was meant to be - // something else. Left as-is rather than guessing a new template-syntax - // character unilaterally - confirm the intended sigil before wiring this - // branch up to a reachable condition. + } else if(variable.ifNext("&")) { renderVariableName(variable, name, modifier); - return getenv(name.c_str()); + const char *envValue = getenv(name.c_str()); + if(envValue == NULL) + throw coreutils::Exception("environment variable is not set."); + coreutils::MString envValueStr(envValue); + return processModifier(envValueStr, modifier); } else if(variable.ifNext("^")) { renderVariableName(variable, name, modifier); return global.cookies.data[name];