comparison mercurial/subrepo.py @ 47803:23921bc857b5 stable

subrepo: compare normalised vfs path Otherwise the realpath call can turn `/` into `\` on windows confusing the check. (We probably needs this in more location) Differential Revision: https://phab.mercurial-scm.org/D11259
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 05 Aug 2021 12:53:36 +0200
parents a125cbbc5782
children 6000f5b25c9b
comparison
equal deleted inserted replaced
47802:bc74cb9a8e40 47803:23921bc857b5
456 r = ctx.repo() 456 r = ctx.repo()
457 root = r.wjoin(util.localpath(path)) 457 root = r.wjoin(util.localpath(path))
458 create = allowcreate and not r.wvfs.exists(b'%s/.hg' % path) 458 create = allowcreate and not r.wvfs.exists(b'%s/.hg' % path)
459 # repository constructor does expand variables in path, which is 459 # repository constructor does expand variables in path, which is
460 # unsafe since subrepo path might come from untrusted source. 460 # unsafe since subrepo path might come from untrusted source.
461 if os.path.realpath(util.expandpath(root)) != root: 461 norm_root = os.path.normcase(root)
462 real_root = os.path.normcase(os.path.realpath(util.expandpath(root)))
463 if real_root != norm_root:
462 raise error.Abort( 464 raise error.Abort(
463 _(b'subrepo path contains illegal component: %s') % path 465 _(b'subrepo path contains illegal component: %s') % path
464 ) 466 )
465 self._repo = hg.repository(r.baseui, root, create=create) 467 self._repo = hg.repository(r.baseui, root, create=create)
466 if self._repo.root != root: 468 if os.path.normcase(self._repo.root) != os.path.normcase(root):
467 raise error.ProgrammingError( 469 raise error.ProgrammingError(
468 b'failed to reject unsafe subrepo ' 470 b'failed to reject unsafe subrepo '
469 b'path: %s (expanded to %s)' % (root, self._repo.root) 471 b'path: %s (expanded to %s)' % (root, self._repo.root)
470 ) 472 )
471 473