hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 5f850989b0dd1c1a582ad43992f0457d86ec4ea2
parent 83084931d245ca0c0dda8fcc0a14badb450293e3
Author: Yasumasa Tada <ytada@spartan.dev>
Date:   Sun, 27 Mar 2022 21:31:07 +0900

fnmatch: don't match brackets incorrectly

Signed-off-by: Yasumasa Tada <ytada@spartan.dev>

Diffstat:
Mfnmatch/+test.ha | 4++++
Mfnmatch/fnmatch.ha | 2+-
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/fnmatch/+test.ha b/fnmatch/+test.ha @@ -74,6 +74,8 @@ const testcases: [_]testcase = [ ("[.a.]", "a", false, []), ("[[:alnum:]]", "7", true, []), + ("[[:alpha:]]", "[", false, []), + ("[[:alpha:]]", "[[", false, []), ("[[alpha:]]", "a]", true, []), ("[[alpha:]]", ":]", true, []), ("[[:alpha:]]", "a", true, []), @@ -101,7 +103,9 @@ const testcases: [_]testcase = [ ("[!-ac]", "b", true, []), ("[![:alnum:]]", "a", false, []), + ("[![:alpha:]]", "[", true, []), ("[![:alnum:]]a", "a]a", false, []), + ("[![:alpha:]]a", "[a", true, []), ("[![:alnum:][:digit:]]", "a", false, []), (".", ".", true, [flags::PERIOD]), diff --git a/fnmatch/fnmatch.ha b/fnmatch/fnmatch.ha @@ -254,7 +254,7 @@ fn match_bracket( inv = true; first = advance_or_err(it)?; }; - let found = (first == c); + let found = (first != '[' && first == c); let last: (rune | void) = first; if (first == ']') { first = advance_or_err(it)?;