forked from boostorg/regex
Updated tests to reflect recent fixes.
Fixed a problem where some invalid expressions would either be accepted, or worse crash. Changed error code for unsupported lookbehind assertions. [SVN r31350]
This commit is contained in:
@ -765,7 +765,7 @@ void basic_regex_creator<charT, traits>::create_startmaps(re_syntax_base* state)
|
|||||||
{
|
{
|
||||||
// Oops error:
|
// Oops error:
|
||||||
if(0 == this->m_pdata->m_status) // update the error code if not already set
|
if(0 == this->m_pdata->m_status) // update the error code if not already set
|
||||||
this->m_pdata->m_status = boost::regex_constants::error_brack;
|
this->m_pdata->m_status = boost::regex_constants::error_bad_pattern;
|
||||||
//
|
//
|
||||||
// clear the expression, we should be empty:
|
// clear the expression, we should be empty:
|
||||||
//
|
//
|
||||||
@ -776,8 +776,8 @@ void basic_regex_creator<charT, traits>::create_startmaps(re_syntax_base* state)
|
|||||||
//
|
//
|
||||||
if(0 == (this->flags() & regex_constants::no_except))
|
if(0 == (this->flags() & regex_constants::no_except))
|
||||||
{
|
{
|
||||||
std::string message = this->m_pdata->m_ptraits->error_string(boost::regex_constants::error_brack);
|
std::string message = this->m_pdata->m_ptraits->error_string(boost::regex_constants::error_bad_pattern);
|
||||||
boost::regex_error e(message, boost::regex_constants::error_brack, 0);
|
boost::regex_error e(message, boost::regex_constants::error_bad_pattern, 0);
|
||||||
e.raise();
|
e.raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -766,6 +766,7 @@ bool basic_regex_parser<charT, traits>::parse_repeat(std::size_t low, std::size_
|
|||||||
case syntax_element_soft_buffer_end:
|
case syntax_element_soft_buffer_end:
|
||||||
case syntax_element_restart_continue:
|
case syntax_element_restart_continue:
|
||||||
case syntax_element_jump:
|
case syntax_element_jump:
|
||||||
|
case syntax_element_startmark:
|
||||||
// can't legally repeat any of the above:
|
// can't legally repeat any of the above:
|
||||||
fail(regex_constants::error_badrepeat, m_position - m_base);
|
fail(regex_constants::error_badrepeat, m_position - m_base);
|
||||||
return false;
|
return false;
|
||||||
@ -1744,6 +1745,9 @@ bool basic_regex_parser<charT, traits>::parse_perl_extension()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case regex_constants::syntax_close_mark:
|
||||||
|
fail(regex_constants::error_badrepeat, m_position - m_base);
|
||||||
|
return false;
|
||||||
default:
|
default:
|
||||||
//
|
//
|
||||||
// lets assume that we have a (?imsx) group and try and parse it:
|
// lets assume that we have a (?imsx) group and try and parse it:
|
||||||
|
@ -129,6 +129,10 @@ void test_partial_match()
|
|||||||
TEST_REGEX_SEARCH("[\\x0-\\xff]{4,}", perl, "xxa", match_default|match_partial, make_array(0, 3, -2, -2));
|
TEST_REGEX_SEARCH("[\\x0-\\xff]{4,}", perl, "xxa", match_default|match_partial, make_array(0, 3, -2, -2));
|
||||||
TEST_REGEX_SEARCH("a{4,}", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
TEST_REGEX_SEARCH("a{4,}", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
||||||
TEST_REGEX_SEARCH("\\w{4,}", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
TEST_REGEX_SEARCH("\\w{4,}", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
||||||
|
TEST_REGEX_SEARCH(".*?<tag>", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
||||||
|
TEST_REGEX_SEARCH("a*?<tag>", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
||||||
|
TEST_REGEX_SEARCH("\\w*?<tag>", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
||||||
|
TEST_REGEX_SEARCH("(\\w)*?<tag>", perl, "aaa", match_default|match_partial, make_array(0, 3, -2, -2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_nosubs()
|
void test_nosubs()
|
||||||
|
@ -39,6 +39,65 @@ void test_simple_repeats()
|
|||||||
TEST_REGEX_SEARCH("\\*", perl, "*", match_default, make_array(0, 1, -2, -2));
|
TEST_REGEX_SEARCH("\\*", perl, "*", match_default, make_array(0, 1, -2, -2));
|
||||||
TEST_REGEX_SEARCH("(ab)*", perl, "abab", match_default, make_array(0, 4, 2, 4, -2, 4, 4, -2, -2));
|
TEST_REGEX_SEARCH("(ab)*", perl, "abab", match_default, make_array(0, 4, 2, 4, -2, 4, 4, -2, -2));
|
||||||
|
|
||||||
|
TEST_INVALID_REGEX("(*)", perl);
|
||||||
|
TEST_INVALID_REGEX("(*)", extended);
|
||||||
|
TEST_INVALID_REGEX("\\(*\\)", basic);
|
||||||
|
TEST_INVALID_REGEX("^*", perl);
|
||||||
|
TEST_INVALID_REGEX("^*", extended);
|
||||||
|
TEST_INVALID_REGEX("$*", perl);
|
||||||
|
TEST_INVALID_REGEX("$*", extended);
|
||||||
|
TEST_INVALID_REGEX("$*", basic);
|
||||||
|
TEST_INVALID_REGEX("\\b*", perl);
|
||||||
|
TEST_INVALID_REGEX("\\B*", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A*", perl);
|
||||||
|
TEST_INVALID_REGEX("\\z*", perl);
|
||||||
|
TEST_INVALID_REGEX("\\Z*", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A*", perl);
|
||||||
|
TEST_INVALID_REGEX("a|*", perl);
|
||||||
|
TEST_INVALID_REGEX("a|*", extended);
|
||||||
|
TEST_INVALID_REGEX("(+)", perl);
|
||||||
|
TEST_INVALID_REGEX("(+)", extended);
|
||||||
|
TEST_INVALID_REGEX("^+", perl);
|
||||||
|
TEST_INVALID_REGEX("^+", extended);
|
||||||
|
TEST_INVALID_REGEX("$+", perl);
|
||||||
|
TEST_INVALID_REGEX("$+", extended);
|
||||||
|
TEST_INVALID_REGEX("\\b+", perl);
|
||||||
|
TEST_INVALID_REGEX("\\B+", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A+", perl);
|
||||||
|
TEST_INVALID_REGEX("\\z+", perl);
|
||||||
|
TEST_INVALID_REGEX("\\Z+", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A+", perl);
|
||||||
|
TEST_INVALID_REGEX("a|+", perl);
|
||||||
|
TEST_INVALID_REGEX("a|+", extended);
|
||||||
|
TEST_INVALID_REGEX("(?)", perl);
|
||||||
|
TEST_INVALID_REGEX("(?)", extended);
|
||||||
|
TEST_INVALID_REGEX("^?", perl);
|
||||||
|
TEST_INVALID_REGEX("^?", extended);
|
||||||
|
TEST_INVALID_REGEX("$?", perl);
|
||||||
|
TEST_INVALID_REGEX("$?", extended);
|
||||||
|
TEST_INVALID_REGEX("\\b?", perl);
|
||||||
|
TEST_INVALID_REGEX("\\B?", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A?", perl);
|
||||||
|
TEST_INVALID_REGEX("\\z?", perl);
|
||||||
|
TEST_INVALID_REGEX("\\Z?", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A?", perl);
|
||||||
|
TEST_INVALID_REGEX("a|?", perl);
|
||||||
|
TEST_INVALID_REGEX("a|?", extended);
|
||||||
|
TEST_INVALID_REGEX("({1,2})", perl);
|
||||||
|
TEST_INVALID_REGEX("({1,2})", extended);
|
||||||
|
TEST_INVALID_REGEX("^{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("^{1,2}", extended);
|
||||||
|
TEST_INVALID_REGEX("${1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("${1,2}", extended);
|
||||||
|
TEST_INVALID_REGEX("\\b{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("\\B{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("\\z{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("\\Z{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("\\A{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("a|{1,2}", perl);
|
||||||
|
TEST_INVALID_REGEX("a|{1,2}", extended);
|
||||||
|
|
||||||
// now try operator + :
|
// now try operator + :
|
||||||
TEST_REGEX_SEARCH("ab+", perl, "a", match_default, make_array(-2, -2));
|
TEST_REGEX_SEARCH("ab+", perl, "a", match_default, make_array(-2, -2));
|
||||||
TEST_REGEX_SEARCH("ab+", perl, "ab", match_default, make_array(0, 2, -2, -2));
|
TEST_REGEX_SEARCH("ab+", perl, "ab", match_default, make_array(0, 2, -2, -2));
|
||||||
|
Reference in New Issue
Block a user