1 // See: https://github.com/rust-lang/regex/issues/48
3 fn invalid_regexes_no_crash() {
4 assert
!(regex_new
!("(*)").is_err());
5 assert
!(regex_new
!("(?:?)").is_err());
6 assert
!(regex_new
!("(?)").is_err());
7 assert
!(regex_new
!("*").is_err());
10 // See: https://github.com/rust-lang/regex/issues/98
12 fn regression_many_repeat_stack_overflow() {
13 let re
= regex
!("^.{1,2500}");
14 assert_eq
!(vec
![(0, 1)], findall
!(re
, "a"));
17 // See: https://github.com/rust-lang/regex/issues/555
19 fn regression_invalid_repetition_expr() {
20 assert
!(regex_new
!("(?m){1,1}").is_err());
23 // See: https://github.com/rust-lang/regex/issues/527
25 fn regression_invalid_flags_expression() {
26 assert
!(regex_new
!("(((?x)))").is_ok());
29 // See: https://github.com/rust-lang/regex/issues/75
30 mat
!(regression_unsorted_binary_search_1
, r
"(?i-u)[a_]+", "A_", Some((0, 2)));
31 mat
!(regression_unsorted_binary_search_2
, r
"(?i-u)[A_]+", "a_", Some((0, 2)));
33 // See: https://github.com/rust-lang/regex/issues/99
34 #[cfg(feature = "unicode-case")]
35 mat
!(regression_negated_char_class_1
, r
"(?i)[^x]", "x", None
);
36 #[cfg(feature = "unicode-case")]
37 mat
!(regression_negated_char_class_2
, r
"(?i)[^x]", "X", None
);
39 // See: https://github.com/rust-lang/regex/issues/101
40 mat
!(regression_ascii_word_underscore
, r
"[[:word:]]", "_", Some((0, 1)));
42 // See: https://github.com/rust-lang/regex/issues/129
44 fn regression_captures_rep() {
45 let re
= regex
!(r
"([a-f]){2}(?P<foo>[x-z])");
46 let caps
= re
.captures(text
!("abx")).unwrap();
47 assert_eq
!(match_text
!(caps
.name("foo").unwrap()), text
!("x"));
50 // See: https://github.com/rust-lang/regex/issues/153
51 mat
!(regression_alt_in_alt1
, r
"ab?|$", "az", Some((0, 1)));
52 mat
!(regression_alt_in_alt2
, r
"^(.*?)(\n|\r\n?|$)", "ab\rcd", Some((0, 3)));
54 // See: https://github.com/rust-lang/regex/issues/169
55 mat
!(regression_leftmost_first_prefix
, r
"z*azb", "azb", Some((0, 3)));
57 // See: https://github.com/rust-lang/regex/issues/76
58 #[cfg(all(feature = "unicode-case", feature = "unicode-gencat"))]
59 mat
!(uni_case_lower_nocase_flag
, r
"(?i)\p{Ll}+", "ΛΘΓΔα", Some((0, 10)));
61 // See: https://github.com/rust-lang/regex/issues/191
62 mat
!(many_alternates
, r
"1|2|3|4|5|6|7|8|9|10|int", "int", Some((0, 3)));
64 // burntsushi was bad and didn't create an issue for this bug.
65 mat
!(anchored_prefix1
, r
"^a[[:^space:]]", "a ", None
);
66 mat
!(anchored_prefix2
, r
"^a[[:^space:]]", "foo boo a ", None
);
67 mat
!(anchored_prefix3
, r
"^-[a-z]", "r-f", None
);
69 // See: https://github.com/rust-lang/regex/issues/204
70 #[cfg(feature = "unicode-perl")]
72 split_on_word_boundary
,
74 r
"Should this (work?)",
85 #[cfg(feature = "unicode-perl")]
98 // See: https://github.com/rust-lang/regex/issues/268
99 matiter
!(partial_anchor
, r
"^a|b", "ba", (0, 1));
101 // See: https://github.com/rust-lang/regex/issues/280
102 ismatch
!(partial_anchor_alternate_begin
, r
"^a|z", "yyyyya", false);
103 ismatch
!(partial_anchor_alternate_end
, r
"a$|z", "ayyyyy", false);
105 // See: https://github.com/rust-lang/regex/issues/289
106 mat
!(lits_unambiguous1
, r
"(ABC|CDA|BC)X", "CDAX", Some((0, 4)));
108 // See: https://github.com/rust-lang/regex/issues/291
111 r
"((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$",
120 // See: https://github.com/rust-lang/regex/issues/271
121 mat
!(endl_or_wb
, r
"(?m:$)|(?-u:\b)", "\u{6084e}", Some((4, 4)));
122 mat
!(zero_or_end
, r
"(?i-u:\x00)|$", "\u{e682f}", Some((4, 4)));
123 mat
!(y_or_endl
, r
"(?i-u:y)|(?m:$)", "\u{b4331}", Some((4, 4)));
124 #[cfg(feature = "unicode-perl")]
125 mat
!(wb_start_x
, r
"(?u:\b)^(?-u:X)", "X", Some((0, 1)));
127 // See: https://github.com/rust-lang/regex/issues/321
128 ismatch
!(strange_anchor_non_complete_prefix
, r
"a^{2}", "", false);
129 ismatch
!(strange_anchor_non_complete_suffix
, r
"${2}a", "", false);
131 // See: https://github.com/BurntSushi/ripgrep/issues/1203
132 ismatch
!(reverse_suffix1
, r
"[0-4][0-4][0-4]000", "153.230000", true);
133 ismatch
!(reverse_suffix2
, r
"[0-9][0-9][0-9]000", "153.230000\n", true);
134 matiter
!(reverse_suffix3
, r
"[0-9][0-9][0-9]000", "153.230000\n", (4, 10));
136 // See: https://github.com/rust-lang/regex/issues/334
137 // See: https://github.com/rust-lang/regex/issues/557
139 captures_after_dfa_premature_end1
,
147 captures_after_dfa_premature_end2
,
154 mat
!(captures_after_dfa_premature_end3
, r
"(aa$)?", "aaz", Some((0, 0)));
156 // See: https://github.com/rust-lang/regex/issues/437
159 r
"typename type\-parameter\-[0-9]+\-[0-9]+::.+",
164 // See: https://github.com/rust-lang/regex/issues/533
166 blank_matches_nothing_between_space_and_tab
,
168 "\u{a}\u{b}\u{c}\u{d}\u{e}\u{f}\
169 \u{10}\u{11}\u{12}\u{13}\u{14}\u{15}\u{16}\u{17}\
170 \u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}",
175 inverted_blank_matches_everything_between_space_and_tab
,
177 "\u{a}\u{b}\u{c}\u{d}\u{e}\u{f}\
178 \u{10}\u{11}\u{12}\u{13}\u{14}\u{15}\u{16}\u{17}\
179 \u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}",
183 // Tests that our Aho-Corasick optimization works correctly. It only
184 // kicks in when we have >32 literals. By "works correctly," we mean that
185 // leftmost-first match semantics are properly respected. That is, samwise
186 // should match, not sam.
189 "samwise|sam|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|\
190 A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z",
195 // See: https://github.com/BurntSushi/ripgrep/issues/1247
197 #[cfg(feature = "unicode-perl")]
198 fn regression_nfa_stops1() {
199 let re
= ::regex
::bytes
::Regex
::new(r
"\bs(?:[ab])").unwrap();
200 assert_eq
!(0, re
.find_iter(b
"s\xE4").count());
203 // See: https://github.com/rust-lang/regex/issues/640
204 #[cfg(feature = "unicode-case")]
214 // See: https://github.com/rust-lang/regex/issues/659
216 // Note that 'Ј' is not 'j', but cyrillic Je
217 // https://en.wikipedia.org/wiki/Je_(Cyrillic)
218 ismatch
!(empty_group_match
, r
"()Ј01", "zЈ01", true);
219 matiter
!(empty_group_find
, r
"()Ј01", "zЈ01", (1, 5));
221 // See: https://github.com/rust-lang/regex/issues/862
222 mat
!(non_greedy_question_literal
, r
"ab??", "ab", Some((0, 1)));