| 348 |
CHECK_EQ(a, ""); |
CHECK_EQ(a, ""); |
| 349 |
} |
} |
| 350 |
|
|
| 351 |
static void TestRecursion(int size, const char *pattern, int match_limit) { |
static void TestRecursion() { |
| 352 |
printf("Testing recursion\n"); |
printf("Testing recursion\n"); |
| 353 |
|
|
| 354 |
// Fill up a string repeating the pattern given |
// Get one string that passes (sometimes), one that never does. |
| 355 |
string domain; |
string text_good("abcdefghijk"); |
| 356 |
domain.resize(size); |
string text_bad("acdefghijkl"); |
| 357 |
int patlen = strlen(pattern); |
|
| 358 |
for (int i = 0; i < size; ++i) { |
// According to pcretest, matching text_good against (\w+)*b |
| 359 |
domain[i] = pattern[i % patlen]; |
// requires match_limit of at least 8192, and match_recursion_limit |
| 360 |
} |
// of at least 37. |
| 361 |
// Just make sure it doesn't crash due to too much recursion. |
|
| 362 |
RE_Options options; |
RE_Options options_ml; |
| 363 |
options.set_match_limit(match_limit); |
options_ml.set_match_limit(8192); |
| 364 |
RE re("([a-zA-Z0-9]|-)+(\\.([a-zA-Z0-9]|-)+)*(\\.)?", options); |
RE re("(\\w+)*b", options_ml); |
| 365 |
re.FullMatch(domain); |
CHECK(re.PartialMatch(text_good) == true); |
| 366 |
|
CHECK(re.PartialMatch(text_bad) == false); |
| 367 |
|
CHECK(re.FullMatch(text_good) == false); |
| 368 |
|
CHECK(re.FullMatch(text_bad) == false); |
| 369 |
|
|
| 370 |
|
options_ml.set_match_limit(1024); |
| 371 |
|
RE re2("(\\w+)*b", options_ml); |
| 372 |
|
CHECK(re2.PartialMatch(text_good) == false); // because of match_limit |
| 373 |
|
CHECK(re2.PartialMatch(text_bad) == false); |
| 374 |
|
CHECK(re2.FullMatch(text_good) == false); |
| 375 |
|
CHECK(re2.FullMatch(text_bad) == false); |
| 376 |
|
|
| 377 |
|
RE_Options options_mlr; |
| 378 |
|
options_mlr.set_match_limit_recursion(50); |
| 379 |
|
RE re3("(\\w+)*b", options_mlr); |
| 380 |
|
CHECK(re3.PartialMatch(text_good) == true); |
| 381 |
|
CHECK(re3.PartialMatch(text_bad) == false); |
| 382 |
|
CHECK(re3.FullMatch(text_good) == false); |
| 383 |
|
CHECK(re3.FullMatch(text_bad) == false); |
| 384 |
|
|
| 385 |
|
options_mlr.set_match_limit_recursion(10); |
| 386 |
|
RE re4("(\\w+)*b", options_mlr); |
| 387 |
|
CHECK(re4.PartialMatch(text_good) == false); |
| 388 |
|
CHECK(re4.PartialMatch(text_bad) == false); |
| 389 |
|
CHECK(re4.FullMatch(text_good) == false); |
| 390 |
|
CHECK(re4.FullMatch(text_bad) == false); |
| 391 |
} |
} |
| 392 |
|
|
| 393 |
// |
// |
| 1046 |
CHECK(!re.error().empty()); |
CHECK(!re.error().empty()); |
| 1047 |
} |
} |
| 1048 |
|
|
| 1049 |
// Test that recursion is stopped: there will be some errors reported |
// Test that recursion is stopped |
| 1050 |
int matchlimit = 5000; |
TestRecursion(); |
|
int bytes = 15 * 1024; // enough to crash if there was no match limit |
|
|
TestRecursion(bytes, ".", matchlimit); |
|
|
TestRecursion(bytes, "a", matchlimit); |
|
|
TestRecursion(bytes, "a.", matchlimit); |
|
|
TestRecursion(bytes, "ab.", matchlimit); |
|
|
TestRecursion(bytes, "abc.", matchlimit); |
|
| 1051 |
|
|
| 1052 |
// Test Options |
// Test Options |
| 1053 |
if (getenv("VERBOSE_TEST") != NULL) |
if (getenv("VERBOSE_TEST") != NULL) |