Skip to content

Commit

Permalink
Fix broken umlauts in filenames (#1339)
Browse files Browse the repository at this point in the history
  • Loading branch information
phihos committed Feb 11, 2021
1 parent 7593d8e commit fe71a8b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 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")[:-1]
except subprocess.CalledProcessError as exc:
_logger.warning(
"Failed to discover yaml files to lint using git: %s",
Expand Down
16 changes: 14 additions & 2 deletions test/TestUtils.py
Expand Up @@ -227,7 +227,7 @@ def test_get_yaml_files_git_verbose(reset_env_var, message_prefix, monkeypatch,
expected_info = (
"ansiblelint",
logging.INFO,
'Discovering files to lint: git ls-files *.yaml *.yml',
'Discovering files to lint: git ls-files -z *.yaml *.yml',
)

assert expected_info in caplog.record_tuples
Expand Down Expand Up @@ -267,6 +267,18 @@ def test_get_yaml_files_silent(is_in_git, monkeypatch, capsys):
)


def test_get_yaml_files_umlaut(monkeypatch):
"""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 Expand Up @@ -300,7 +312,7 @@ def test_cli_auto_detect(capfd):
out, err = capfd.readouterr()

# Confirmation that it runs in auto-detect mode
assert "Discovering files to lint: git ls-files *.yaml *.yml" in err
assert "Discovering files to lint: git ls-files -z *.yaml *.yml" in err
# An expected rule match from our examples
assert (
"examples/playbooks/empty_playbook.yml:0: "
Expand Down

0 comments on commit fe71a8b

Please sign in to comment.