diff rust/hg-core/src/filepatterns.rs @ 49605:b3480822a251 stable

matcher: do not prepend '.*' to pattern using ^ after flags Since the previous commit (fixing wider issue), the code generated strange regex. This is now fixed and tested.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 16 Nov 2022 15:39:10 +0100
parents 086b0c4f8663
children ccb6cfb0f2c0
line wrap: on
line diff
--- a/rust/hg-core/src/filepatterns.rs	Wed Nov 16 16:38:42 2022 +0100
+++ b/rust/hg-core/src/filepatterns.rs	Wed Nov 16 15:39:10 2022 +0100
@@ -205,7 +205,14 @@
                         &b"(?"[..],
                         &pattern[s + 2..e - 1],
                         &b":"[..],
-                        &b".*"[..],
+                        if pattern[e] == b'^'
+                            || pattern[e] == b'*'
+                            || pattern[e..].starts_with(b".*")
+                        {
+                            &b""[..]
+                        } else {
+                            &b".*"[..]
+                        },
                         &pattern[e..],
                         &b")"[..],
                     ]
@@ -752,5 +759,14 @@
             .unwrap(),
             Some(b"(?ia:.*ba{2}r)".to_vec()),
         );
+        assert_eq!(
+            build_single_regex(&IgnorePattern::new(
+                PatternSyntax::RelRegexp,
+                b"(?ia)^ba{2}r",
+                Path::new("")
+            ))
+            .unwrap(),
+            Some(b"(?ia:^ba{2}r)".to_vec()),
+        );
     }
 }