From 10b794bb96a3e1eecde5a1324de1e40e781fa077 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Wed, 16 Jan 2013 03:55:59 +0100 Subject: [PATCH] Creating empty glob_list_t matches everything MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is more than creating a glob_list_t containing just ‘*’, as the latter does not match hidden files, so it is more like ‘{*,.*}’, which is a bit arcane, so I think it’s better to allow using an empty list in cases where you wish to match everything (but the API accepts a glob list for filtering purposes). --- Frameworks/regexp/src/glob.cc | 3 +++ Frameworks/regexp/tests/t_glob_list.cc | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Frameworks/regexp/src/glob.cc b/Frameworks/regexp/src/glob.cc index 166da0c0..374b3f2c 100644 --- a/Frameworks/regexp/src/glob.cc +++ b/Frameworks/regexp/src/glob.cc @@ -241,6 +241,9 @@ namespace path bool glob_list_t::exclude (std::string const& path, kPathItemType itemType, bool defaultResult) const { + if(_globs.empty()) + return false; + for(auto record : _globs) { if((itemType == kPathItemAny || record.item_type == kPathItemAny || itemType == record.item_type) && record.glob.does_match(path)) diff --git a/Frameworks/regexp/tests/t_glob_list.cc b/Frameworks/regexp/tests/t_glob_list.cc index 3c65a681..20d2b209 100644 --- a/Frameworks/regexp/tests/t_glob_list.cc +++ b/Frameworks/regexp/tests/t_glob_list.cc @@ -3,6 +3,24 @@ class GlobListTests : public CxxTest::TestSuite { public: + void test_empty_glob_list () + { + path::glob_list_t globs; + TS_ASSERT(globs.include("foo")); + TS_ASSERT(globs.include("bar")); + TS_ASSERT(globs.include(".foo")); + TS_ASSERT(globs.include(".bar")); + } + + void test_non_empty_glob_list () + { + path::glob_list_t globs("*"); + TS_ASSERT(globs.include("foo")); + TS_ASSERT(globs.include("bar")); + TS_ASSERT(globs.exclude(".foo")); + TS_ASSERT(globs.exclude(".bar")); + } + void test_glob_list () { path::glob_list_t globs;