Skip to content

Commit

Permalink
Fix broken umlauts in filenames (ansible#1339)
Browse files Browse the repository at this point in the history
  • Loading branch information
phihos committed Feb 11, 2021
1 parent 7593d8e commit 99baf3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions examples/playbooks/with-umlaut-ä.yml
@@ -0,0 +1,5 @@
---
- hosts:
- localhost
roles:
- name: node
4 changes: 2 additions & 2 deletions src/ansiblelint/file_utils.py
Expand Up @@ -166,15 +166,15 @@ 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

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",
Expand Down
12 changes: 12 additions & 0 deletions test/TestUtils.py
Expand Up @@ -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'])
Expand Down

0 comments on commit 99baf3c

Please sign in to comment.