##// END OF EJS Templates
matcher: fix the issue with regex inline-flag in rust oo...
marmoute -
r50499:086b0c4f stable
parent child Browse files
Show More
@@ -171,6 +171,10 b' pub fn parse_pattern_syntax('
171 }
171 }
172 }
172 }
173
173
174 lazy_static! {
175 static ref FLAG_RE: Regex = Regex::new(r"^\(\?[aiLmsux]+\)").unwrap();
176 }
177
174 /// Builds the regex that corresponds to the given pattern.
178 /// Builds the regex that corresponds to the given pattern.
175 /// If within a `syntax: regexp` context, returns the pattern,
179 /// If within a `syntax: regexp` context, returns the pattern,
176 /// otherwise, returns the corresponding regex.
180 /// otherwise, returns the corresponding regex.
@@ -193,7 +197,22 b' fn _build_single_regex(entry: &IgnorePat'
193 {
197 {
194 return pattern.to_owned();
198 return pattern.to_owned();
195 }
199 }
196 [&b".*"[..], pattern].concat()
200 match FLAG_RE.find(pattern) {
201 Some(mat) => {
202 let s = mat.start();
203 let e = mat.end();
204 [
205 &b"(?"[..],
206 &pattern[s + 2..e - 1],
207 &b":"[..],
208 &b".*"[..],
209 &pattern[e..],
210 &b")"[..],
211 ]
212 .concat()
213 }
214 None => [&b".*"[..], pattern].concat(),
215 }
197 }
216 }
198 PatternSyntax::Path | PatternSyntax::RelPath => {
217 PatternSyntax::Path | PatternSyntax::RelPath => {
199 if pattern == b"." {
218 if pattern == b"." {
@@ -703,4 +722,35 b' mod tests {'
703 Some(br"[^/]*\.o(?:/|$)".to_vec()),
722 Some(br"[^/]*\.o(?:/|$)".to_vec()),
704 );
723 );
705 }
724 }
725
726 #[test]
727 fn test_build_single_relregex() {
728 assert_eq!(
729 build_single_regex(&IgnorePattern::new(
730 PatternSyntax::RelRegexp,
731 b"^ba{2}r",
732 Path::new("")
733 ))
734 .unwrap(),
735 Some(b"^ba{2}r".to_vec()),
736 );
737 assert_eq!(
738 build_single_regex(&IgnorePattern::new(
739 PatternSyntax::RelRegexp,
740 b"ba{2}r",
741 Path::new("")
742 ))
743 .unwrap(),
744 Some(b".*ba{2}r".to_vec()),
745 );
746 assert_eq!(
747 build_single_regex(&IgnorePattern::new(
748 PatternSyntax::RelRegexp,
749 b"(?ia)ba{2}r",
750 Path::new("")
751 ))
752 .unwrap(),
753 Some(b"(?ia:.*ba{2}r)".to_vec()),
754 );
755 }
706 }
756 }
@@ -90,8 +90,7 b' flag in a pattern should affect that pat'
90 $ echo 're:.HGIGNORE' >> .hgignore
90 $ echo 're:.HGIGNORE' >> .hgignore
91 $ hg status
91 $ hg status
92 A dir/b.o
92 A dir/b.o
93 ? .hgignore (no-rust !)
93 ? .hgignore
94 ? .hgignore (rust missing-correct-output !)
95 ? a.c
94 ? a.c
96 ? syntax
95 ? syntax
97
96
General Comments 0
You need to be logged in to leave comments. Login now