Skip to content

Commit 75600e3

Browse files
authored
Merge pull request #163 from boostorg/issue151
Disallow repeating a case-change group.
2 parents 2be85f3 + b10c089 commit 75600e3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/boost/regex/v5/basic_regex_parser.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ bool basic_regex_parser<charT, traits>::parse_repeat(std::size_t low, std::size_
10341034
case syntax_element_jump:
10351035
case syntax_element_startmark:
10361036
case syntax_element_backstep:
1037+
case syntax_element_toggle_case:
10371038
// can't legally repeat any of the above:
10381039
fail(regex_constants::error_badrepeat, m_position - m_base);
10391040
return false;
@@ -3107,7 +3108,13 @@ bool basic_regex_parser<charT, traits>::unwind_alts(std::ptrdiff_t last_paren_st
31073108
m_alt_jumps.pop_back();
31083109
this->m_pdata->m_data.align();
31093110
re_jump* jmp = static_cast<re_jump*>(this->getaddress(jump_offset));
3110-
BOOST_REGEX_ASSERT(jmp->type == syntax_element_jump);
3111+
if (jmp->type != syntax_element_jump)
3112+
{
3113+
// Something really bad happened, this used to be an assert,
3114+
// but we'll make it an error just in case we should ever get here.
3115+
fail(regex_constants::error_unknown, this->m_position - this->m_base, "Internal logic failed while compiling the expression, probably you added a repeat to something non-repeatable!");
3116+
return false;
3117+
}
31113118
jmp->alt.i = this->m_pdata->m_data.size() - jump_offset;
31123119
}
31133120
return true;

test/regress/test_simple_repeats.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,5 +496,13 @@ void test_pocessive_repeats()
496496
TEST_INVALID_REGEX("(ab + + +)", perl | mod_x);
497497
TEST_INVALID_REGEX("(ab + + ?)", perl | mod_x);
498498

499+
#ifndef BOOST_REGEX_CXX03
500+
// Some bug cases from https://github.com/boostorg/regex/issues/151
501+
TEST_INVALID_REGEX("a|?+", perl | mod_x);
502+
TEST_INVALID_REGEX("(?xi)a|?+", perl | mod_x);
503+
TEST_INVALID_REGEX("(?xi)a|#\r*", perl | mod_x);
504+
TEST_INVALID_REGEX("(?xi)|#\r*", perl | mod_x);
505+
TEST_INVALID_REGEX("(?xi)|?+#\r*", perl | mod_x);
506+
#endif
499507
}
500508

0 commit comments

Comments
 (0)