# HG changeset patch # User Raphaël Gomès # Date 2021-09-01 15:40:25 # Node ID 1e00834491a563ac0886e65c291ce52cb054fcd6 # Parent d919b0ca8449367977e40fd6202fb500486e83f7 rhg-cat: fallback when detecting `.` or `..` path segments We do not normalize paths correctly yet, so exclude the shortcuts. Differential Revision: https://phab.mercurial-scm.org/D11378 diff --git a/rust/rhg/src/commands/cat.rs b/rust/rhg/src/commands/cat.rs --- a/rust/rhg/src/commands/cat.rs +++ b/rust/rhg/src/commands/cat.rs @@ -46,8 +46,13 @@ pub fn run(invocation: &crate::CliInvoca let mut files = vec![]; for file in file_args.iter() { + let normalized = cwd.join(&file); // TODO: actually normalize `..` path segments etc? - let normalized = cwd.join(&file); + let dotted = normalized.components().any(|c| c.as_os_str() == ".."); + if file == &"." || dotted { + let message = "`..` or `.` path segment"; + return Err(CommandError::unsupported(message)); + } let stripped = normalized .strip_prefix(&working_directory) // TODO: error message for path arguments outside of the repo diff --git a/tests/test-rhg.t b/tests/test-rhg.t --- a/tests/test-rhg.t +++ b/tests/test-rhg.t @@ -199,6 +199,17 @@ Fallback to Python [252] +Fallback with shell path segments + $ $NO_FALLBACK rhg cat . + unsupported feature: `..` or `.` path segment + [252] + $ $NO_FALLBACK rhg cat .. + unsupported feature: `..` or `.` path segment + [252] + $ $NO_FALLBACK rhg cat ../.. + unsupported feature: `..` or `.` path segment + [252] + Requirements $ $NO_FALLBACK rhg debugrequirements dotencode