Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We do not normalize paths correctly yet, so exclude the shortcuts.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11378

AFFECTED FILES
  rust/rhg/src/commands/cat.rs
  tests/test-rhg.t

CHANGE DETAILS

diff --git a/tests/test-rhg.t b/tests/test-rhg.t
--- a/tests/test-rhg.t
+++ b/tests/test-rhg.t
@@ -196,6 +196,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
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 @@
 
     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



To: Alphare, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to