From 527e8bf778ed39085c5841583580ee7b8474ff7d Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Thu, 31 Oct 2024 16:05:46 -0700 Subject: [PATCH] Fixed read tag to throw exception on file error unstead of looping forever. --- Global.cpp | 12 ++++++------ __read.cpp | 2 ++ tests/testjet.jet | 4 ++-- tests/testvar.jet | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Global.cpp b/Global.cpp index 7f51b76..46f4a98 100644 --- a/Global.cpp +++ b/Global.cpp @@ -75,12 +75,12 @@ namespace jet { renderVariableName(variable, modifier, modifier, lvariables); return; } - else if(variable.startsWith("$[")) { - name << getVariable(variable, lvariables); - } - else if(variable.startsWith("#[")) { - name << getVariable(variable, lvariables); - } + else if(variable.startsWith("$[") || variable.startsWith("#[")) + name << getVariable(variable, lvariables); + else if(variable.ifNext("]")) + return; + else if(!variable.ifNextInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-")) + throw coreutils::Exception("invalid variable name."); } return; } diff --git a/__read.cpp b/__read.cpp index 359fe2f..659991c 100644 --- a/__read.cpp +++ b/__read.cpp @@ -14,6 +14,8 @@ namespace jet { if(hasContainer) throw coreutils::Exception("read tag does not have a container."); fd = open(variables["file"].c_str(), O_RDONLY); + if(fd < 0) + throw coreutils::Exception("file name is not found."); global.variables[variables["name"]].read(fd); close(fd); } diff --git a/tests/testjet.jet b/tests/testjet.jet index 04e5089..90a1e25 100755 --- a/tests/testjet.jet +++ b/tests/testjet.jet @@ -1,4 +1,4 @@ -#!./jet-2.0 +#!../jet-2.0
This is a comment and should not show up in the output. @@ -54,7 +54,7 @@ $[rc] $[ls] - + $[filex] $[file] $[fullpath] $[noext] diff --git a/tests/testvar.jet b/tests/testvar.jet index dbbc255..39d4ecc 100755 --- a/tests/testvar.jet +++ b/tests/testvar.jet @@ -6,6 +6,7 @@ +$[$test] $[$[ix]var$[ix]] $[var$[ix]] $[var$[ix]var]