From d9254599f9bb47632313ecb90c5f281ceca5da3a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 19 Feb 2020 22:36:26 -0500 Subject: manifest/tests: get them passing under Windows We also need to check more things in the manifest/project handlers, and use platform_utils in a few places to address Windows behavior. Drop Python 2.7 from Windows testing as it definitely doesn't work and we won't be fixing it. Change-Id: I83d00ee9f1612312bb3f7147cb9535fc61268245 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256113 Tested-by: Mike Frysinger Reviewed-by: Jonathan Nieder Reviewed-by: David Pursehouse --- manifest_xml.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'manifest_xml.py') diff --git a/manifest_xml.py b/manifest_xml.py index 41628003..fe0735a8 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -1010,19 +1010,30 @@ class XmlManifest(object): # Assume paths might be used on case-insensitive filesystems. path = path.lower() + # Split up the path by its components. We can't use os.path.sep exclusively + # as some platforms (like Windows) will convert / to \ and that bypasses all + # our constructed logic here. Especially since manifest authors only use + # / in their paths. + resep = re.compile(r'[/%s]' % re.escape(os.path.sep)) + parts = resep.split(path) + # Some people use src="." to create stable links to projects. Lets allow # that but reject all other uses of "." to keep things simple. - parts = path.split(os.path.sep) if parts != ['.']: for part in set(parts): if part in {'.', '..', '.git'} or part.startswith('.repo'): return 'bad component: %s' % (part,) - if not symlink and path.endswith(os.path.sep): + if not symlink and resep.match(path[-1]): return 'dirs not allowed' + # NB: The two abspath checks here are to handle platforms with multiple + # filesystem path styles (e.g. Windows). norm = os.path.normpath(path) - if norm == '..' or norm.startswith('../') or norm.startswith(os.path.sep): + if (norm == '..' or + (len(norm) >= 3 and norm.startswith('..') and resep.match(norm[0])) or + os.path.isabs(norm) or + norm.startswith('/')): return 'path cannot be outside' @classmethod -- cgit v1.2.3-54-g00ecf