summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/expr.c4
-rw-r--r--tests/test_expr.c4
2 files changed, 8 insertions, 0 deletions
diff --git a/common/expr.c b/common/expr.c
index fc694cc..7fa4f84 100644
--- a/common/expr.c
+++ b/common/expr.c
@@ -93,6 +93,8 @@ MUST_USE static const char *parse_dollar_expression(
if (parse_name(str,ptr,varname,sizeof(varname))==NULL)
return NULL;
varvalue=expander(varname,expander_arg);
+ if (varvalue==NULL)
+ varvalue="";
if (str[*ptr]=='}')
{
/* simple substitute */
@@ -148,6 +150,8 @@ MUST_USE static const char *parse_dollar_expression(
if (parse_name(str,ptr,varname,sizeof(varname))==NULL)
return NULL;
varvalue=expander(varname,expander_arg);
+ if (varvalue==NULL)
+ varvalue="";
if (strlen(varvalue)>=buflen)
return NULL;
strcpy(buffer,varvalue);
diff --git a/tests/test_expr.c b/tests/test_expr.c
index 3ee9773..1ea4f8d 100644
--- a/tests/test_expr.c
+++ b/tests/test_expr.c
@@ -50,6 +50,8 @@ static const char *expanderfn(const char *name,void UNUSED(*expander_attr))
{
if (strcmp(name,"empty")==0)
return "";
+ if (strcmp(name,"null")==0)
+ return NULL;
else
return "foobar";
}
@@ -65,6 +67,8 @@ static void test_expr_parse(void)
assertstreq(buffer,"");
assert(expr_parse("$foo1$empty-$foo2",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
assertstreq(buffer,"foobar-foobar");
+ assert(expr_parse("$foo1+$null+$foo2",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
+ assertstreq(buffer,"foobar++foobar");
assert(expr_parse("${test1}\\$",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
assertstreq(buffer,"foobar$");
assert(expr_parse("${test1:-default}",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);