summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorandybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 15:19:37 +0000
committerandybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-06 15:19:37 +0000
commit5ab19bb96d097595cc176cfbf6a245deee44b6ec (patch)
tree9b4762137a815cd9c2bbd16ce7fadd7fb4007b83 /base
parent9f600be3dcb474d0224d611d517fe7edc7b7e874 (diff)
downloadchromium_src-5ab19bb96d097595cc176cfbf6a245deee44b6ec.zip
chromium_src-5ab19bb96d097595cc176cfbf6a245deee44b6ec.tar.gz
chromium_src-5ab19bb96d097595cc176cfbf6a245deee44b6ec.tar.bz2
fixes issue 52839 (MatchPattern timeout)
Fixes issue 52839 by converting consecutive wildcards (******) into one wildcard (*) in MatchPattern. BUG=52839 TEST=MatchPattern Original patch from issue 3608005 (Jon Stritar) Review URL: http://codereview.chromium.org/3551016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61644 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/string_util.cc4
-rw-r--r--base/string_util.h1
-rw-r--r--base/string_util_unittest.cc6
3 files changed, 11 insertions, 0 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 83ba148..e1b80f0 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -1074,6 +1074,10 @@ static bool MatchPatternT(const CHAR* eval, const CHAR* eval_end,
// This is a *, try to match all the possible substrings with the remainder
// of the pattern.
if (pattern[0] == '*') {
+ // Collapse duplicate wild cards (********** into *) so that the
+ // method does not recurse unnecessarily. http://crbug.com/52839
+ EatWildcard(&next_pattern, pattern_end, next);
+
while (eval != eval_end) {
if (MatchPatternT(eval, eval_end, next_pattern, pattern_end,
depth + 1, next))
diff --git a/base/string_util.h b/base/string_util.h
index 7079127..41a0cd4 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -558,6 +558,7 @@ bool ElideString(const std::wstring& input, int max_len, std::wstring* output);
// string can contain wildcards like * and ?
// The backslash character (\) is an escape character for * and ?
// We limit the patterns to having a max of 16 * or ? characters.
+// ? matches 0 or 1 character, while * matches 0 or more characters.
bool MatchPattern(const base::StringPiece& string,
const base::StringPiece& pattern);
bool MatchPattern(const string16& string, const string16& pattern);
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 617b0eb..0f7d79d 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -988,6 +988,12 @@ TEST(StringUtilTest, MatchPatternTest) {
UTF8ToUTF16("*.com")));
EXPECT_TRUE(MatchPattern(UTF8ToUTF16("Hello*1234"),
UTF8ToUTF16("He??o\\*1*")));
+
+ // This test verifies that consecutive wild cards are collapsed into 1
+ // wildcard (when this doesn't occur, MatchPattern reaches it's maximum
+ // recursion depth).
+ EXPECT_TRUE(MatchPattern(UTF8ToUTF16("Hello"),
+ UTF8ToUTF16("He********************************o")));
}
TEST(StringUtilTest, LcpyTest) {