From d6694af190ad3c24d1da2c5e98475573babc168d Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Wed, 27 May 2026 11:07:08 +0100 Subject: [PATCH] Fix char_range with equal bounds matching nothing Previously, legal single-char ranges like `[a-a]` silently matched nothing but are now included. Also add a testcase for a singleton range. --- src/glob.ml | 2 +- test/test.ml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/glob.ml b/src/glob.ml index 5ccdc08..19ce3df 100644 --- a/src/glob.ml +++ b/src/glob.ml @@ -57,7 +57,7 @@ let compile_char_class = function let i = Char.code c in let c1_code = Char.code c1 in let c2_code = Char.code c2 in - if c1_code < c2_code then i >= c1_code && i <= c2_code else false + if c1_code <= c2_code then i >= c1_code && i <= c2_code else false let compile_char_classes css = let rec loop cs v = diff --git a/test/test.ml b/test/test.ml index 08a22bf..791e7e3 100644 --- a/test/test.ml +++ b/test/test.ml @@ -74,7 +74,11 @@ let test_matches () = matches ~msg:"char-range" Glob.[ range 'a' 'z'; ranges [ Chars [ 'd'; 'e' ] ]; string "llo.txt" ] [ "hello.txt"; "world.txt" ] - [ "hello.txt" ] + [ "hello.txt" ]; + matches ~msg:"char-range-singleton" + Glob.[ range 'a' 'a'; string "bc" ] + [ "abc"; "bbc" ] + [ "abc" ] let test_split () = let split ?(msg = "same split") t (p, v) = -- 2.51.2