commit 548180b

shrub  ·  2026-05-06 09:14:04 +0000 UTC
parent a98ab69
fix variable expansion when it looks like a function by checking against an actual list
1 files changed,  +31, -4
+31, -4
 1@@ -413,6 +413,16 @@ struct func {
 2 	} fn;
 3 };
 4 
 5+static const char *const allfuncs[] = {
 6+	"abspath", "addprefix", "addsuffix", "and", "basename",
 7+	"call", "dir", "error", "eval", "file", "filter",
 8+	"filter-out", "findstring", "firstword", "flavor", "foreach",
 9+	"guile", "if", "info", "intcmp", "join", "lastword", "let",
10+	"notdir", "or", "origin", "patsubst", "realpath", "shell",
11+	"sort", "strip", "subst", "suffix", "value", "warning",
12+	"wildcard", "word", "wordlist", "words", 0,
13+};
14+
15 static const struct func funcs[] = {
16     {"wildcard", FNEXP1, {.f1 = fnwildcard}},
17     {"shell", FNEXP1, {.f1 = fnshell}},
18@@ -537,10 +547,22 @@ funcref(struct EvalCtx *ctx, const char *s, size_t n)
19 	return 0;
20 }
21 
22+static int
23+isfunc(const char *s, size_t n)
24+{
25+	size_t i;
26+
27+	for (i = 0; allfuncs[i]; i++) {
28+		if (strlen(allfuncs[i]) == n && strncmp(allfuncs[i], s, n) == 0)
29+			return 1;
30+	}
31+	return 0;
32+}
33+
34 static char *
35 expandref(struct EvalCtx *ctx, const char *s, size_t n)
36 {
37-	size_t colon, eq;
38+	size_t colon, eq, i;
39 	char *val;
40 
41 	if (isplainvar(s, n))
42@@ -550,12 +572,17 @@ expandref(struct EvalCtx *ctx, const char *s, size_t n)
43 	val = funcref(ctx, s, n);
44 	if (val)
45 		return val;
46-	{
47-		char *detail = xstrndup(s, n);
48+	for (i = 0; i < n && !isspace((unsigned char)s[i]); i++)
49+		;
50+	if (i < n && isfunc(s, i)) {
51+		char *detail;
52+
53+		detail = xstrndup(s, n);
54 		evalerr(ctx, "i don't know how to handle that yet", detail);
55 		free(detail);
56+		return xstrdup("");
57 	}
58-	return xstrdup("");
59+	return expandvarref(ctx, s, n);
60 }
61 
62 char *