From 72de727d0ec5319c28a00a24a2db245f354e0ae4 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sat, 13 Feb 2010 13:35:04 -0800 Subject: [PATCH] globs: * and ? should not match path-separator --- basis/globs/globs-tests.factor | 7 ++++++- basis/globs/globs.factor | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/basis/globs/globs-tests.factor b/basis/globs/globs-tests.factor index bdc0623d54..eceb6bab7b 100644 --- a/basis/globs/globs-tests.factor +++ b/basis/globs/globs-tests.factor @@ -1,4 +1,4 @@ -USING: tools.test globs ; +USING: tools.test globs io.pathnames ; IN: globs.tests [ f ] [ "abd" "fdf" glob-matches? ] unit-test @@ -17,3 +17,8 @@ IN: globs.tests [ f ] [ "foo." "*.{xml,txt}" glob-matches? ] unit-test [ t ] [ "foo." "*.{,xml,txt}" glob-matches? ] unit-test [ t ] [ "foo.{" "*.{" glob-matches? ] unit-test + +[ f ] [ "foo" "bar" append-path "*" glob-matches? ] unit-test +[ t ] [ "foo" "bar" append-path "*" "*" append-path glob-matches? ] unit-test +[ f ] [ "foo" "bar" append-path "foo?bar" glob-matches? ] unit-test +[ t ] [ "foo" "bar" append-path "fo?" "bar" append-path glob-matches? ] unit-test diff --git a/basis/globs/globs.factor b/basis/globs/globs.factor index cac7fd9a2f..47c8fca528 100644 --- a/basis/globs/globs.factor +++ b/basis/globs/globs.factor @@ -1,9 +1,12 @@ ! Copyright (C) 2007, 2009 Slava Pestov, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: sequences kernel regexp.combinators strings unicode.case -peg.ebnf regexp arrays ; +USING: sequences io.pathnames kernel regexp.combinators +strings unicode.case peg.ebnf regexp arrays ; IN: globs +: not-path-separator ( -- sep ) + "[^" path-separator "]" 3append ; foldable + EBNF: Character = "\\" .:c => [[ c 1string ]] @@ -24,8 +27,8 @@ CharClass = "^"?:n Ranges:e => [[ e n [ ] when ]] AlternationBody = Concatenation:c "," AlternationBody:a => [[ a c prefix ]] | Concatenation => [[ 1array ]] -Element = "*" => [[ R/ .*/ ]] - | "?" => [[ R/ ./ ]] +Element = "*" => [[ not-path-separator ]] + | "?" => [[ not-path-separator ]] | "[" CharClass:c "]" => [[ c ]] | "{" AlternationBody:b "}" => [[ b ]] | Character