Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/filepatterns.rs @ 50856:2b4bcdc948e7
rust: don't escape spaces in regex
Spaces are not in fact a regex special character, and escaping them is
not correct.
author | Spencer Baugh <sbaugh@janestreet.com> |
---|---|
date | Wed, 02 Aug 2023 09:59:49 -0400 |
parents | df6dfad5009a |
children | 090658724abf |
comparison
equal
deleted
inserted
replaced
50855:df6dfad5009a | 50856:2b4bcdc948e7 |
---|---|
22 use std::vec::Vec; | 22 use std::vec::Vec; |
23 | 23 |
24 lazy_static! { | 24 lazy_static! { |
25 static ref RE_ESCAPE: Vec<Vec<u8>> = { | 25 static ref RE_ESCAPE: Vec<Vec<u8>> = { |
26 let mut v: Vec<Vec<u8>> = (0..=255).map(|byte| vec![byte]).collect(); | 26 let mut v: Vec<Vec<u8>> = (0..=255).map(|byte| vec![byte]).collect(); |
27 let to_escape = b"()[]{}?*+-|^$\\.&~# \t\n\r\x0b\x0c"; | 27 let to_escape = b"()[]{}?*+-|^$\\.&~#\t\n\r\x0b\x0c"; |
28 for byte in to_escape { | 28 for byte in to_escape { |
29 v[*byte as usize].insert(0, b'\\'); | 29 v[*byte as usize].insert(0, b'\\'); |
30 } | 30 } |
31 v | 31 v |
32 }; | 32 }; |
639 let untouched = | 639 let untouched = |
640 br#"!"%',/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz"#; | 640 br#"!"%',/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz"#; |
641 assert_eq!(escape_pattern(untouched), untouched.to_vec()); | 641 assert_eq!(escape_pattern(untouched), untouched.to_vec()); |
642 // All escape codes | 642 // All escape codes |
643 assert_eq!( | 643 assert_eq!( |
644 escape_pattern(br#"()[]{}?*+-|^$\\.&~# \t\n\r\v\f"#), | 644 escape_pattern(br#"()[]{}?*+-|^$\\.&~#\t\n\r\v\f"#), |
645 br#"\(\)\[\]\{\}\?\*\+\-\|\^\$\\\\\.\&\~\#\ \\t\\n\\r\\v\\f"# | 645 br#"\(\)\[\]\{\}\?\*\+\-\|\^\$\\\\\.\&\~\#\\t\\n\\r\\v\\f"# |
646 .to_vec() | 646 .to_vec() |
647 ); | 647 ); |
648 } | 648 } |
649 | 649 |
650 #[test] | 650 #[test] |