Skip to content

Commit

Permalink
Allow quantifiable assertions in non unicode mode (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Jan 28, 2024
1 parent c95a802 commit f3127f9
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ where
'(' => {
if self.try_consume_str("(?=") {
// Positive lookahead.
quantifier_allowed = false;
quantifier_allowed = !self.flags.unicode;
result.push(self.consume_lookaround_assertion(LookaroundParams {
negate: false,
backwards: false,
})?);
} else if self.try_consume_str("(?!") {
// Negative lookahead.
quantifier_allowed = false;
quantifier_allowed = !self.flags.unicode;
result.push(self.consume_lookaround_assertion(LookaroundParams {
negate: true,
backwards: false,
Expand Down
90 changes: 90 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,3 +1650,93 @@ fn test_class_invalid_control_character_tc(tc: TestConfig) {
tc.test_match_succeeds("[\\c\u{0}]", "", "c");
tc.test_match_succeeds("[\\c\u{0}]", "", "\u{0}");
}

#[test]
fn test_quantifiable_assertion_not_followed_by() {
test_with_configs(test_quantifiable_assertion_not_followed_by_tc)
}

/// 262 test/annexB/language/literals/regexp/quantifiable-assertion-not-followed-by.js
fn test_quantifiable_assertion_not_followed_by_tc(tc: TestConfig) {
tc.compile(r#"[a-e](?!Z)*"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("a");
tc.compile(r#"[a-e](?!Z)+"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
tc.compile(r#"[a-e](?!Z)?"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("a");
tc.compile(r#"[a-e](?!Z){2}"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
tc.compile(r#"[a-e](?!Z){2,}"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
tc.compile(r#"[a-e](?!Z){2,3}"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
tc.compile(r#"[a-e](?!Z)*?"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("a");
tc.compile(r#"[a-e](?!Z)+?"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
tc.compile(r#"[a-e](?!Z)??"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("a");
tc.compile(r#"[a-e](?!Z){2}?"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
tc.compile(r#"[a-e](?!Z){2,}?"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
tc.compile(r#"[a-e](?!Z){2,3}?"#)
.match1f(r#"aZZZZ bZZZ cZZ dZ e"#)
.test_eq("e");
}

#[test]
fn test_quantifiable_assertion_followed_by() {
test_with_configs(test_quantifiable_assertion_followed_by_tc)
}

/// 262 test/annexB/language/literals/regexp/quantifiable-assertion-followed-by.js
fn test_quantifiable_assertion_followed_by_tc(tc: TestConfig) {
tc.compile(r#".(?=Z)*"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("a");
tc.compile(r#".(?=Z)+"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
tc.compile(r#".(?=Z)?"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("a");
tc.compile(r#".(?=Z){2}"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
tc.compile(r#".(?=Z){2,}"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
tc.compile(r#".(?=Z){2,3}"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
tc.compile(r#".(?=Z)*?"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("a");
tc.compile(r#".(?=Z)+?"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
tc.compile(r#".(?=Z)??"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("a");
tc.compile(r#".(?=Z){2}?"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
tc.compile(r#".(?=Z){2,}?"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
tc.compile(r#".(?=Z){2,3}?"#)
.match1f(r#"a bZ cZZ dZZZ eZZZZ"#)
.test_eq("b");
}

0 comments on commit f3127f9

Please sign in to comment.