diff --git "a/examples/playbooks/with-umlaut-\303\244.yml" "b/examples/playbooks/with-umlaut-\303\244.yml" new file mode 100644 index 00000000000..3a18e9422fd --- /dev/null +++ "b/examples/playbooks/with-umlaut-\303\244.yml" @@ -0,0 +1,5 @@ +--- +- hosts: + - localhost + roles: + - name: node diff --git a/src/ansiblelint/file_utils.py b/src/ansiblelint/file_utils.py index dbc22084b46..0793d98fac7 100644 --- a/src/ansiblelint/file_utils.py +++ b/src/ansiblelint/file_utils.py @@ -166,7 +166,7 @@ def __repr__(self) -> str: def get_yaml_files(options: Namespace) -> Dict[str, Any]: """Find all yaml files.""" # git is preferred as it also considers .gitignore - git_command = ['git', 'ls-files', '*.yaml', '*.yml'] + git_command = ['git', 'ls-files', '-z', '*.yaml', '*.yml'] _logger.info("Discovering files to lint: %s", ' '.join(git_command)) out = None @@ -174,7 +174,7 @@ def get_yaml_files(options: Namespace) -> Dict[str, Any]: try: out = subprocess.check_output( git_command, stderr=subprocess.STDOUT, universal_newlines=True - ).splitlines() + ).split("\x00") except subprocess.CalledProcessError as exc: _logger.warning( "Failed to discover yaml files to lint using git: %s", diff --git a/test/TestUtils.py b/test/TestUtils.py index 966281e0562..4405652cac1 100644 --- a/test/TestUtils.py +++ b/test/TestUtils.py @@ -267,6 +267,18 @@ def test_get_yaml_files_silent(is_in_git, monkeypatch, capsys): ) +def test_get_yaml_files_umlaut(monkeypatch, capsys): + """Verify that filenames containing German umlauts are not garbled by the get_yaml_files.""" + options = cli.get_config([]) + test_dir = Path(__file__).resolve().parent + lint_path = test_dir / '..' / 'examples' / 'playbooks' + + monkeypatch.chdir(str(lint_path)) + files = file_utils.get_yaml_files(options) + assert '"with-umlaut-\\303\\244.yml"' not in files + assert 'with-umlaut-รค.yml' in files + + def test_logger_debug(caplog): """Test that the double verbosity arg causes logger to be DEBUG.""" options = cli.get_config(['-vv'])