aboutsummaryrefslogtreecommitdiff
path: root/ctemplates.c
diff options
context:
space:
mode:
Diffstat (limited to 'ctemplates.c')
-rw-r--r--ctemplates.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/ctemplates.c b/ctemplates.c
index e9e36ff..bc91441 100644
--- a/ctemplates.c
+++ b/ctemplates.c
@@ -580,12 +580,16 @@ parse_if(struct TMPL_token* head, struct TMPL_buf* errbuf){
t->TMPL_tag.ifelse.varname = name;
/*Find the name to check against*/
int testval_offset = kmp(start_of_attribs,head->length, ATTRIBUTE_VALUE,ATTRIBUTE_VALUE_LENGTH);
- char* start_of_value = start_of_attribs + testval_offset + ATTRIBUTE_VALUE_LENGTH;
- size_t value_length = get_quoted_string(start_of_value,head->length);
- char* value = (char*)malloc(sizeof(char)*value_length);
- memcpy(value,start_of_value,value_length);
- value[value_length] = '\0';
- t->TMPL_tag.ifelse.testval = value;
+ if(testval_offset == -1){
+ t->TMPL_tag.ifelse.testval = NULL;
+ }else{
+ char* start_of_value = start_of_attribs + testval_offset + ATTRIBUTE_VALUE_LENGTH;
+ size_t value_length = get_quoted_string(start_of_value,head->length);
+ char* value = (char*)malloc(sizeof(char)*value_length);
+ memcpy(value,start_of_value,value_length);
+ value[value_length] = '\0';
+ t->TMPL_tag.ifelse.testval = value;
+ }
/*Find the true branch*/
struct TMPL_token* cursor = head->next;
int nest_level = 0;
@@ -916,9 +920,7 @@ render_if(struct TMPL_templates* t, struct TMPL_tagnode* node, struct TMPL_varli
int err = hashmap_get(varlist->map,varname,(void**)&vi);
struct TMPL_tagnode* cursor;
if(err == MAP_OK){
- if(testval == NULL){/*Use this if as an existance check*/
-
- }else if(strcmp(vi->item.s, testval) == 0){
+ if(testval == NULL || strcmp(vi->item.s, testval) == 0){
cursor = node->TMPL_tag.ifelse.tbranch;
while(cursor != NULL){
render_any(t,cursor,varlist);
@@ -1078,7 +1080,8 @@ TMPL_free_tagnode(struct TMPL_tagnode* tn){
case tag_elseif:
case tag_else:
free(tn->TMPL_tag.ifelse.varname);
- free(tn->TMPL_tag.ifelse.testval);
+ if(tn->TMPL_tag.ifelse.testval != NULL)
+ free(tn->TMPL_tag.ifelse.testval);
TMPL_free_tagnode(tn->TMPL_tag.ifelse.tbranch);
if(tn->TMPL_tag.ifelse.fbranch){
TMPL_free_tagnode(tn->TMPL_tag.ifelse.fbranch);