From 3c867680578c2d3f17be01f0769601572bafded9 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 22:25:08 +0000 Subject: [PATCH] Let a glob class range start at a leading ] [patch] ToGlobCharacterList refused to read a leading "]" as the start of a range, so "[]-a]" became the set "]", "-", "a" instead of the range "]".."a", missing "^", "_" and "`" and matching "-". FindGlobClassEnd already keeps a leading "]" from closing the class, so the range check needs no exception. Fixes #179 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW547mxaz1R4r27gAVm --- TextFilter.Test/TextFilterTests.cs | 2 ++ TextFilter/TextFilter.cs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/TextFilter.Test/TextFilterTests.cs b/TextFilter.Test/TextFilterTests.cs index 3250a64..3d72e01 100644 --- a/TextFilter.Test/TextFilterTests.cs +++ b/TextFilter.Test/TextFilterTests.cs @@ -1004,6 +1004,8 @@ public void ExpandGlobClassesRejectsClassesThatCannotBeListed(string token) => [DataRow("file[0-9a-]", "file5 filea file-", "fileb file_")] [DataRow("[]a-]", "a - ]", "b [")] [DataRow("[!]a-]", "b [", "a - ]")] + [DataRow("[]-a]", "] ^ _ ` a", "- b [")] + [DataRow("[!]-a]", "- b [", "] ^ _ ` a")] [DataRow("[!-#]", "a $ ! \"", "- #")] public void GlobClassMatchesEveryMemberOfEveryRange(string pattern, string matching, string notMatching) { diff --git a/TextFilter/TextFilter.cs b/TextFilter/TextFilter.cs index 927c00c..9c320a1 100644 --- a/TextFilter/TextFilter.cs +++ b/TextFilter/TextFilter.cs @@ -575,7 +575,8 @@ private static bool SpansPathSeparator(char first, char last) => while (i < content.Length) { char first = content[i]; - bool isRange = i + 2 < content.Length && content[i + 1] == '-' && !(i == 0 && first == ']'); + // A leading "]" can start a range too: "[]-a]" is "]".."a", as in POSIX. + bool isRange = i + 2 < content.Length && content[i + 1] == '-'; if (!isRange) { members.Add(first);