threads / patch / 61382

patch, 8 partsrefs: disallow dash in pseudoref syntax

Subject: [PATCH 4/8] refs: disallow dash in pseudoref syntax

## tl;dr

One message between Apr 29, 2024 and Apr 29, 2024. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Jeff King· Apr 29, 2024, 08:23 UTC · lore

Our is_pseudoref_syntax() function allows upper-case letters, underscore ("_") and dash ("-"). Our glossary definition is vague on the allowed punctuation, but I don't think we have ever used a pseudoref with anything but an underscore. And the existing open-coded syntax check in refname_is_safe() allows only underscores.

The logic comes from 266b18273a (refs: add ref_type function, 2015-07-31), but I couldn't find any comment on the dash in the commit message or the list discussion. It's used mostly for is_pseudoref(), which further requires that the name either end in "_HEAD" or be one of a specific set of "irregular" pseudorefs.

So I don't think we'd ever see a dash in the real world (you'd need to have "FOO-BAR_HEAD"). Let's tighten this up now so that the function is consistent with (and can be used in) other spots.

Signed-off-by: Jeff King <peff@peff.net>
---
 refs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to refs.c +1 −1
diff --git a/refs.c b/refs.c
index d3d21ecd43..b202dca904 100644
--- a/refs.c
+++ b/refs.c
@@ -169,7 +169,7 @@ static int is_pseudoref_syntax(const char *refname)
 	const char *c;
 
 	for (c = refname; *c; c++) {
-		if (!isupper(*c) && *c != '-' && *c != '_')
+		if (!isupper(*c) && *c != '_')
 			return 0;
 	}
 
-- 
2.45.0.rc1.416.gbe2a76c799

← back to recent threads