Skip to content

Commit

Permalink
fix: decode answers file content explicitly as UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
sisp committed Feb 17, 2025
1 parent d735c8b commit 21b486c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion copier/subproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _raw_answers(self) -> AnyByStrDict:
"""Get last answers, loaded raw as yaml."""
try:
return yaml.safe_load(
(self.local_abspath / self.answers_relpath).read_text()
(self.local_abspath / self.answers_relpath).read_text("utf-8")
)
except OSError:
return {}
Expand Down
33 changes: 33 additions & 0 deletions tests/test_updatediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,3 +1768,36 @@ def test_gitignore_file_unignored(
# Otherwise, it should succeed.
run_update(dst_path=dst, overwrite=True)
assert "_commit: v3" in (dst / ".copier-answers.yml").read_text()


def test_update_with_answers_with_umlaut(
tmp_path_factory: pytest.TempPathFactory,
) -> None:
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))

with local.cwd(src):
build_file_tree(
{
"copier.yml": (
"""\
umlaut:
type: str
"""
),
"{{ _copier_conf.answers_file }}.jinja": "{{ _copier_answers|to_nice_yaml }}",
}
)
git_init("v1")
git("tag", "v1")

run_copy(str(src), dst, data={"umlaut": "äöü"}, overwrite=True)
answers_file = dst / ".copier-answers.yml"
answers = yaml.safe_load(answers_file.read_text("utf-8"))
assert answers["umlaut"] == "äöü"

with local.cwd(dst):
git_init("v1")

run_update(dst, skip_answered=True, overwrite=True)
answers = yaml.safe_load(answers_file.read_text("utf-8"))
assert answers["umlaut"] == "äöü"

0 comments on commit 21b486c

Please sign in to comment.