Skip to content

Commit 810d9e6

Browse files
authored
Merge pull request #292 from BurntSushi/fix-291
Fixes a bug introduced by the fix in 630049.
2 parents 0b39dd3 + 0471c74 commit 810d9e6

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Cargo.lock
33
bench-log
44
.*.swp
55
wiki
6+
tags

regex-syntax/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ description = "A regular expression parser."
1111
[dev-dependencies]
1212
quickcheck = "0.2"
1313
rand = "0.3"
14+
15+
[profile.test]
16+
codegen-units = 8

regex-syntax/src/literals.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,12 @@ impl Literals {
250250
}
251251
} else {
252252
if let Some(i) = position(&lit2, &candidate) {
253-
candidate.truncate(i);
254-
candidate.cut();
255253
lit2.cut();
254+
let mut new_candidate = candidate.clone();
255+
new_candidate.truncate(i);
256+
new_candidate.cut();
257+
old.push(new_candidate);
258+
candidate.clear();
256259
}
257260
}
258261
// Oops, the candidate is already represented in the set.
@@ -1385,14 +1388,17 @@ mod tests {
13851388
vec![M("Mo'"), M("Mu'"), M("Mo"), M("Mu")],
13861389
vec![C("Mo"), C("Mu")]);
13871390
test_unamb!(unambiguous11,
1388-
vec![M("zazb"), M("azb")], vec![C("azb"), C("z")]);
1391+
vec![M("zazb"), M("azb")], vec![C("a"), C("z")]);
13891392
test_unamb!(unambiguous12, vec![M("foo"), C("foo")], vec![C("foo")]);
13901393
test_unamb!(unambiguous13,
13911394
vec![M("ABCX"), M("CDAX"), M("BCX")],
13921395
vec![C("A"), C("BCX"), C("CD")]);
13931396
test_unamb!(unambiguous14,
13941397
vec![M("IMGX"), M("MVIX"), M("MGX"), M("DSX")],
13951398
vec![M("DSX"), C("I"), C("MGX"), C("MV")]);
1399+
test_unamb!(unambiguous15,
1400+
vec![M("IMG_"), M("MG_"), M("CIMG")],
1401+
vec![C("C"), C("I"), C("MG_")]);
13961402

13971403

13981404
// ************************************************************************

tests/regression.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ ismatch!(partial_anchor_alternate_begin, u!(r"^a|z"), "yyyyya", false);
7070
ismatch!(partial_anchor_alternate_end, u!(r"a$|z"), "ayyyyy", false);
7171

7272
// See: https://github.com/rust-lang-nursery/regex/issues/289
73-
mat!(lits_unambiguous, u!(r"(ABC|CDA|BC)X"), "CDAX", Some((0, 4)));
73+
mat!(lits_unambiguous1, u!(r"(ABC|CDA|BC)X"), "CDAX", Some((0, 4)));
74+
75+
// See: https://github.com/rust-lang-nursery/regex/issues/291
76+
mat!(lits_unambiguous2, u!(r"((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$"),
77+
"CIMG2341", Some((0, 8)), Some((0, 4)), None, Some((0, 4)), Some((4, 8)));

0 commit comments

Comments
 (0)