From 3a8e4cf54d40cfecadb700c9600417e727639096 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 11 May 2018 10:30:21 +0700 Subject: [PATCH] Fix off by 1 in Path.is_descendant --- src/stdune/path.ml | 2 +- test/unit-tests/path.mlt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stdune/path.ml b/src/stdune/path.ml index d30e23e3..ec8fd4ad 100644 --- a/src/stdune/path.ml +++ b/src/stdune/path.ml @@ -206,7 +206,7 @@ module Local = struct let of_len = String.length of_ in let t_len = String.length t in (t_len = of_len && t = of_) || - (t_len >= of_len && t.[of_len] = '/' && String.is_prefix t ~prefix:of_) + (t_len > of_len && t.[of_len] = '/' && String.is_prefix t ~prefix:of_) let reach t ~from = let rec loop t from = diff --git a/test/unit-tests/path.mlt b/test/unit-tests/path.mlt index 0d7525a0..974d8bf7 100644 --- a/test/unit-tests/path.mlt +++ b/test/unit-tests/path.mlt @@ -37,17 +37,17 @@ Path.(is_descendant (r "foo/") ~of_:(r "foo")) Path.(is_descendant (r "foo") ~of_:(r "bar")) [%%expect{| -Exception: Invalid_argument "index out of bounds". +- : bool = false |}] Path.(is_descendant (r "foo") ~of_:(r "bar/")) [%%expect{| -Exception: Invalid_argument "index out of bounds". +- : bool = false |}] Path.(is_descendant (r "foo/") ~of_:(r "bar")) [%%expect{| -Exception: Invalid_argument "index out of bounds". +- : bool = false |}] Path.(is_descendant (r "glob/foo") ~of_:(r "glob"))