rhg-cat: fallback when detecting `.` or `..` path segments
authorRaphaël Gomès <rgomes@octobus.net>
Wed, 01 Sep 2021 17:40:25 +0200
changeset 48073 1e00834491a5
parent 48072 d919b0ca8449
child 48074 4a6fa6b6f079
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
rust/rhg/src/commands/cat.rs
tests/test-rhg.t
--- a/rust/rhg/src/commands/cat.rs	Wed Sep 01 16:13:25 2021 +0200
+++ b/rust/rhg/src/commands/cat.rs	Wed Sep 01 17:40:25 2021 +0200
@@ -46,8 +46,13 @@
 
     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
--- a/tests/test-rhg.t	Wed Sep 01 16:13:25 2021 +0200
+++ b/tests/test-rhg.t	Wed Sep 01 17:40:25 2021 +0200
@@ -199,6 +199,17 @@
   
   [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