From 9a2995bb4d8c30c15a74a68e440782e7cc2404d5 Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Wed, 27 May 2026 11:09:16 +0100 Subject: [PATCH] Allow star to match zero characters POSIX `*` matches any sequence including the empty one, so for example "*.txt" failed to match ".txt" and "*" failed to match "". --- src/glob.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/glob.ml b/src/glob.ml index 17539a3..3eb6326 100644 --- a/src/glob.ml +++ b/src/glob.ml @@ -215,12 +215,12 @@ let matches ?options glob path = | Some l -> l - i | None -> rest_len in + (* Star may consume 0..break_len characters: try each length in + order and let the suffix decide. *) let rec backtrack j = - if j >= break_len then None - else - begin if matches (i + j + 1) path rest then Some j - else backtrack (j + 1) - end + if matches (i + j) path rest then Some j + else if j >= break_len then None + else backtrack (j + 1) in Option.is_some (backtrack 0) | Question :: rest -> -- 2.51.2