diff --git a/bdebstrap b/bdebstrap index 2c3b270..338423c 100755 --- a/bdebstrap +++ b/bdebstrap @@ -426,14 +426,16 @@ def parse_args(args): # pylint: disable=too-many-statements args.components = [c for l in args.components for c in re.split(",| ", l) if c] if args.architectures: args.architectures = [a for l in args.architectures for a in re.split(",| ", l) if a] - args.mirrors = [m for mirror_list in args.mirrors for m in mirror_list.split(",") if m] + args.mirrors = [ + m.strip() for mirror_list in args.mirrors for m in mirror_list.split(",") if m.strip() + ] # Positional arguments override optional arguments (or extent them in case of "mirrors") if args.suite_positional: args.suite = args.suite_positional if args.target_positional: args.target = args.target_positional - args.mirrors += [m for m in args.mirrors_positional if m] + args.mirrors += [m.strip() for m in args.mirrors_positional if m.strip()] del args.suite_positional del args.target_positional del args.mirrors_positional diff --git a/tests/test_config.py b/tests/test_config.py index faab5b7..91131e3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -110,6 +110,28 @@ def test_malformed_env(self): with self.assertRaises(SystemExit): parse_args(["--env", "invalid"]) + def test_mirrors_with_spaces(self): + """Test --mirrors with leading/trailing spaces.""" + args = parse_args( + [ + "--mirrors", + " deb http://deb.debian.org/debian unstable main\t , \t, " + "deb http://deb.debian.org/debian unstable non-free\t", + "--mirrors", + "\tdeb http://deb.debian.org/debian unstable contrib ", + ] + ) + self.assertDictContainsSubset( + { + "mirrors": [ + "deb http://deb.debian.org/debian unstable main", + "deb http://deb.debian.org/debian unstable non-free", + "deb http://deb.debian.org/debian unstable contrib", + ], + }, + args.__dict__, + ) + def test_optional_args(self): """Test optional arguments (which also have positional ones).""" args = parse_args(