Skip to content

Commit d007874

Browse files
committed
Correctly rewrite bounded repetitions following an explicit class
Character classes were never unstacked so a bounded repetition following a class would never be rewritten. This yields no time savings on the bench run, maximum RSS and peak memory do seem to go down by a few MiB (we're talking 129 to 126 or so) but it's not 100% reliable.
1 parent 2a0a85c commit d007874

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ua-parser/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn rewrite_regex(re: &str) -> std::borrow::Cow<'_, str> {
664664
inclass += 1;
665665
}
666666
']' if !escape => {
667-
inclass += 1;
667+
inclass -= 1;
668668
}
669669
// no need for special cases because regex allows nesting
670670
// character classes, whereas js or python don't \o/
@@ -721,6 +721,18 @@ mod test_rewrite_regex {
721721
assert_eq!(rewrite(".{1,300}x"), ".+x");
722722
}
723723

724+
#[test]
725+
fn rewrite_all_repetitions() {
726+
assert_eq!(
727+
rewrite("; {0,2}(T-(?:07|[^0][0-9])[^;/]{1,100}?)(?: Build|\\) AppleWebKit)"),
728+
"; {0,2}(T-(?:07|[^0][0-9])[^;/]+?)(?: Build|\\) AppleWebKit)",
729+
);
730+
assert_eq!(
731+
rewrite("; {0,2}(SH\\-?[0-9][0-9][^;/]{1,100}|SBM[0-9][^;/]{1,100}?)(?: Build|\\) AppleWebKit)"),
732+
"; {0,2}(SH\\-?[0-9][0-9][^;/]+|SBM[0-9][^;/]+?)(?: Build|\\) AppleWebKit)",
733+
)
734+
}
735+
724736
#[test]
725737
fn ignore_non_repetitions() {
726738
assert_eq!(

0 commit comments

Comments
 (0)