Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow quantifiable assertions in non unicode mode #86

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
Loading