Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/sparse.rs @ 52267:77b95a4abbb2 stable
narrow: stricter validation of narrowspec patterns in rhg
Do the same whitespace-at-the-edge validation in rhg that we do in Python.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Tue, 28 Jan 2025 17:29:59 +0000 |
parents | ae1ab6d71f4a |
children | 42f78c859dd1 |
line wrap: on
line diff
--- a/rust/hg-core/src/sparse.rs Fri Jan 10 16:14:40 2025 +0000 +++ b/rust/hg-core/src/sparse.rs Tue Jan 28 17:29:59 2025 +0000 @@ -87,6 +87,10 @@ /// An invalid pattern prefix was given to the narrow spec. Includes the /// entire pattern for context. InvalidNarrowPrefix(Vec<u8>), + /// Narrow/sparse patterns can not begin or end in whitespace + /// because the Python parser strips the whitespace when parsing + /// the config file. + WhitespaceAtEdgeOfPattern(Vec<u8>), #[from] HgError(HgError), #[from] @@ -136,6 +140,20 @@ VALID_PREFIXES.join(", ") )), }, + SparseConfigError::WhitespaceAtEdgeOfPattern(vec) => { + HgError::Abort { + message: String::from_utf8_lossy(&format_bytes!( + b"narrow pattern with whitespace at the edge: {}", + vec + )) + .to_string(), + detailed_exit_code: STATE_ERROR, + hint: Some( + "narrow patterns can't begin or end in whitespace" + .to_string(), + ), + } + } SparseConfigError::HgError(hg_error) => hg_error, SparseConfigError::PatternError(pattern_error) => HgError::Abort { message: pattern_error.to_string(),