[PATCH] opener: forbid paths ending with directory separator (issue 2507) (Revised)
Jim Hague
jim.hague at acm.org
Thu Dec 2 06:36:55 CST 2010
# HG changeset patch
# User Jim Hague <jim.hague at acm.org>
# Date 1291293230 0
# Branch stable
# Node ID 89c66b190bf33da61eb86195a80cf22ebf91dd0b
# Parent 5e51254ad4d4c80669f462e310b2677f2b3c54a7
opener: forbid paths ending with directory separator (issue2507)
If Linux is asked to open a filename with a trailing directory separator,
e.g. "foo/", the open fails with EISDIR. On AIX, the open succeeds, opening
file "foo". This causes test-mq-qnew to fail on AIX.
Fix by adding 'ends with directory separator' to the conditions checked
by the path auditor. Change test to expect auditor fail message.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -488,6 +488,7 @@
'''ensure that a filesystem path contains no banned components.
the following properties of a path are checked:
+ - ends with a directory separator
- under top-level .hg
- starts at the root of a windows drive
- contains ".."
@@ -505,6 +506,9 @@
def __call__(self, path):
if path in self.audited:
return
+ # AIX ignores "/" at end of path, others raise EISDIR.
+ if endswithsep(path):
+ raise Abort(_("path ends in directory separator: %s") % path)
normpath = os.path.normcase(path)
parts = splitpath(normpath)
if (os.path.splitdrive(path)[0]
diff --git a/tests/test-mq-qnew.t b/tests/test-mq-qnew.t
--- a/tests/test-mq-qnew.t
+++ b/tests/test-mq-qnew.t
@@ -107,7 +107,7 @@
abort: "foo#bar" cannot be used as the name of a patch
abort: "foo:bar" cannot be used as the name of a patch
% qnew with name containing slash
- abort: cannot write patch "foo/": (Is a|No such file or) directory (re)
+ abort: path ends in directory separator: foo/
abort: "foo" already exists as a directory
foo/bar.patch
popping foo/bar.patch
@@ -172,7 +172,7 @@
abort: "foo#bar" cannot be used as the name of a patch
abort: "foo:bar" cannot be used as the name of a patch
% qnew with name containing slash
- abort: cannot write patch "foo/": (Is a|No such file or) directory (re)
+ abort: path ends in directory separator: foo/
abort: "foo" already exists as a directory
foo/bar.patch
popping foo/bar.patch
More information about the Mercurial-devel
mailing list