Mercurial > public > mercurial-scm > hg
comparison mercurial/pathutil.py @ 23598:c02a05cc6f5e stable
pathauditor: check for codepoints ignored on OS X
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Tue, 16 Dec 2014 13:08:17 -0500 |
parents | 8dd17b19e722 |
children | 6dad422ecc5a |
comparison
equal
deleted
inserted
replaced
23597:7a5bcd471f2e | 23598:c02a05cc6f5e |
---|---|
1 import os, errno, stat | 1 import os, errno, stat |
2 | 2 |
3 import encoding | |
3 import util | 4 import util |
4 from i18n import _ | 5 from i18n import _ |
6 | |
7 def _lowerclean(s): | |
8 return encoding.hfsignoreclean(s.lower()) | |
5 | 9 |
6 class pathauditor(object): | 10 class pathauditor(object): |
7 '''ensure that a filesystem path contains no banned components. | 11 '''ensure that a filesystem path contains no banned components. |
8 the following properties of a path are checked: | 12 the following properties of a path are checked: |
9 | 13 |
37 # AIX ignores "/" at end of path, others raise EISDIR. | 41 # AIX ignores "/" at end of path, others raise EISDIR. |
38 if util.endswithsep(path): | 42 if util.endswithsep(path): |
39 raise util.Abort(_("path ends in directory separator: %s") % path) | 43 raise util.Abort(_("path ends in directory separator: %s") % path) |
40 parts = util.splitpath(path) | 44 parts = util.splitpath(path) |
41 if (os.path.splitdrive(path)[0] | 45 if (os.path.splitdrive(path)[0] |
42 or parts[0].lower() in ('.hg', '.hg.', '') | 46 or _lowerclean(parts[0]) in ('.hg', '.hg.', '') |
43 or os.pardir in parts): | 47 or os.pardir in parts): |
44 raise util.Abort(_("path contains illegal component: %s") % path) | 48 raise util.Abort(_("path contains illegal component: %s") % path) |
45 if '.hg' in path.lower(): | 49 if '.hg' in _lowerclean(path): |
46 lparts = [p.lower() for p in parts] | 50 lparts = [_lowerclean(p.lower()) for p in parts] |
47 for p in '.hg', '.hg.': | 51 for p in '.hg', '.hg.': |
48 if p in lparts[1:]: | 52 if p in lparts[1:]: |
49 pos = lparts.index(p) | 53 pos = lparts.index(p) |
50 base = os.path.join(*parts[:pos]) | 54 base = os.path.join(*parts[:pos]) |
51 raise util.Abort(_("path '%s' is inside nested repo %r") | 55 raise util.Abort(_("path '%s' is inside nested repo %r") |