mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-27 10:18:12 +00:00
Merge pull request #2015 from ThomasWaldmann/fix-location-regex
fix bad parsing of wrong syntax
This commit is contained in:
commit
ca0c1dab11
2 changed files with 14 additions and 3 deletions
|
@ -823,11 +823,17 @@ class Location:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# path must not contain :: (it ends at :: or string end), but may contain single colons.
|
# path must not contain :: (it ends at :: or string end), but may contain single colons.
|
||||||
# to avoid ambiguities with other regexes, it must also not start with ":".
|
# to avoid ambiguities with other regexes, it must also not start with ":" nor with "//" nor with "ssh://".
|
||||||
path_re = r"""
|
path_re = r"""
|
||||||
(?!:) # not starting with ":"
|
(?!(:|//|ssh://)) # not starting with ":" or // or ssh://
|
||||||
(?P<path>([^:]|(:(?!:)))+) # any chars, but no "::"
|
(?P<path>([^:]|(:(?!:)))+) # any chars, but no "::"
|
||||||
"""
|
"""
|
||||||
|
# abs_path must not contain :: (it ends at :: or string end), but may contain single colons.
|
||||||
|
# it must start with a / and that slash is part of the path.
|
||||||
|
abs_path_re = r"""
|
||||||
|
(?P<path>(/([^:]|(:(?!:)))+)) # start with /, then any chars, but no "::"
|
||||||
|
"""
|
||||||
|
|
||||||
# optional ::archive_name at the end, archive name must not contain "/".
|
# optional ::archive_name at the end, archive name must not contain "/".
|
||||||
# borg mount's FUSE filesystem creates one level of directories from
|
# borg mount's FUSE filesystem creates one level of directories from
|
||||||
# the archive names and of course "/" is not valid in a directory name.
|
# the archive names and of course "/" is not valid in a directory name.
|
||||||
|
@ -842,7 +848,7 @@ class Location:
|
||||||
(?P<proto>ssh):// # ssh://
|
(?P<proto>ssh):// # ssh://
|
||||||
""" + optional_user_re + r""" # user@ (optional)
|
""" + optional_user_re + r""" # user@ (optional)
|
||||||
(?P<host>[^:/]+)(?::(?P<port>\d+))? # host or host:port
|
(?P<host>[^:/]+)(?::(?P<port>\d+))? # host or host:port
|
||||||
""" + path_re + optional_archive_re, re.VERBOSE) # path or path::archive
|
""" + abs_path_re + optional_archive_re, re.VERBOSE) # path or path::archive
|
||||||
|
|
||||||
file_re = re.compile(r"""
|
file_re = re.compile(r"""
|
||||||
(?P<proto>file):// # file://
|
(?P<proto>file):// # file://
|
||||||
|
|
|
@ -134,6 +134,11 @@ def test_format_path(self, monkeypatch):
|
||||||
location_time2 = Location('/some/path::archive{now:%s}')
|
location_time2 = Location('/some/path::archive{now:%s}')
|
||||||
assert location_time1.archive != location_time2.archive
|
assert location_time1.archive != location_time2.archive
|
||||||
|
|
||||||
|
def test_bad_syntax(self):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
# this is invalid due to the 2nd colon, correct: 'ssh://user@host/path'
|
||||||
|
Location('ssh://user@host:/path')
|
||||||
|
|
||||||
|
|
||||||
class TestLocationWithEnv:
|
class TestLocationWithEnv:
|
||||||
def test_ssh(self, monkeypatch):
|
def test_ssh(self, monkeypatch):
|
||||||
|
|
Loading…
Reference in a new issue