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

Require \ for unicode-escapes in named captures #67

Closed
Closed
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 @@ -932,7 +932,7 @@ where
let mut group_name = String::new();

if let Some(mut c) = self.next().and_then(char::from_u32) {
if self.try_consume('u') {
if c == '\\' && self.try_consume('u') {
if let Some(escaped) = self.try_escape_unicode_sequence().and_then(char::from_u32) {
c = escaped;
} else {
Expand All @@ -954,7 +954,7 @@ where

loop {
if let Some(mut c) = self.next().and_then(char::from_u32) {
if self.try_consume('u') {
if c == '\\' && self.try_consume('u') {
if let Some(escaped) =
self.try_escape_unicode_sequence().and_then(char::from_u32)
{
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,10 @@ fn run_regexp_named_capture_groups_tc(tc: TestConfig) {
tc.compilef(r#"(?<a>a)(?<b>b)\k<a>"#, "").match1_named_group("aba", "a").test_eq("a");
tc.compilef(r#"(?<a>a)(?<b>b)\k<a>"#, "").match1_named_group("aba", "b").test_eq("b");

// regression test for
// https://github.com/ridiculousfish/regress/issues/41
tc.compilef(r#"(?<au>.)"#, "").match1_named_group("a", "au").test_eq("a");

// Make sure that escapes are parsed correctly in the fast capture group parser.
// This pattern should fail in unicode mode, because there is a backreference without a capture group.
// If the `\]` is not handled correctly in the parser, the following `(.)` may be parsed as a capture group.
Expand Down