From b5b12171e1e710f90258dc5237069b1010e14c96 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 29 Nov 2024 12:10:17 +0900 Subject: [PATCH] Fix indexing in `IF` Expressions like `{{{!IF SomeVar[2]==true}}}` should work properly now. --- example_config/example.config | 23 +++++++++++++++++++++++ src/http_template.c | 6 ++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/example_config/example.config b/example_config/example.config index 9e911c7..b7328bd 100644 --- a/example_config/example.config +++ b/example_config/example.config @@ -36,6 +36,29 @@ HTML=''' {{{!ENDIF}}} {{{!ENDFOREACH}}} +Again with IFs:
+ +{{{!IF EachIfTest_Array[0]==true}}} + EachIfTest_Array entry is true.
+{{{!ELSE}}} + EachIfTest_Array entry is false.
+{{{!ENDIF}}} +{{{!IF EachIfTest_Array[1]==true}}} + EachIfTest_Array entry is true.
+{{{!ELSE}}} + EachIfTest_Array entry is false.
+{{{!ENDIF}}} +{{{!IF EachIfTest_Array[2]==true}}} + EachIfTest_Array entry is true.
+{{{!ELSE}}} + EachIfTest_Array entry is false.
+{{{!ENDIF}}} +{{{!IF EachIfTest_Array[3]==true}}} + EachIfTest_Array entry is true.
+{{{!ELSE}}} + EachIfTest_Array entry is false.
+{{{!ENDIF}}} +

Test IF/FOREACH Expr

diff --git a/src/http_template.c b/src/http_template.c index 6d0cb57..ef17aeb 100644 --- a/src/http_template.c +++ b/src/http_template.c @@ -229,10 +229,12 @@ int c_simple_http_internal_parse_if_expression( fprintf(stderr, "ERROR No closing \"]\"! %s\n", var); return 1; } else if ( - idx + 1 < var_size && var[idx] == '!' && var[idx + 1] == '=') { + idx + 2 < var_size && var[idx + 1] == '!' && var[idx + 2] == '=') { + ++idx; break; } else if ( - idx + 1 < var_size && var[idx] == '=' && var[idx + 1] == '=') { + idx + 2 < var_size && var[idx + 1] == '=' && var[idx + 2] == '=') { + ++idx; break; } else { fprintf(stderr, "ERROR Invalid expression after \"]\"! %s\n", var);