From f903eea713e9040153e7454879a86b7a34711e32 Mon Sep 17 00:00:00 2001 From: Willy Blandin Date: Tue, 20 Oct 2020 18:24:31 +0200 Subject: [PATCH] set explicit encoding when reading and writing hex config fixes tsloughter/rebar3_hex#184 --- src/rebar_hex_repos.erl | 5 +++-- test/rebar_pkg_repos_SUITE.erl | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rebar_hex_repos.erl b/src/rebar_hex_repos.erl index 7b1aa908..b9d4bca4 100644 --- a/src/rebar_hex_repos.erl +++ b/src/rebar_hex_repos.erl @@ -163,5 +163,6 @@ update_auth_config(Updates, State) -> Config = auth_config(State), AuthConfigFile = auth_config_file(State), ok = filelib:ensure_dir(AuthConfigFile), - NewConfig = iolist_to_binary([io_lib:print(maps:merge(Config, Updates)) | ".\n"]), - ok = file:write_file(AuthConfigFile, NewConfig). + NewConfig = iolist_to_binary(["%% coding: utf-8", io_lib:nl(), + io_lib:print(maps:merge(Config, Updates)), ".", io_lib:nl()]), + ok = file:write_file(AuthConfigFile, NewConfig, [{encoding, utf8}]). diff --git a/test/rebar_pkg_repos_SUITE.erl b/test/rebar_pkg_repos_SUITE.erl index bb9d9d11..e972ecf2 100644 --- a/test/rebar_pkg_repos_SUITE.erl +++ b/test/rebar_pkg_repos_SUITE.erl @@ -9,7 +9,8 @@ all() -> [default_repo, repo_merging, repo_replacing, - auth_merging, auth_config_errors, organization_merging, {group, resolve_version}]. + auth_read_write_read, auth_merging, auth_config_errors, organization_merging, + {group, resolve_version}]. groups() -> [{resolve_version, [use_first_repo_match, use_exact_with_hash, fail_repo_update, @@ -271,6 +272,11 @@ auth_config_errors(_Config) -> ?assertEqual(undefined, maps:get(write_key, DefaultRepo, undefined)), ok. +auth_read_write_read(_Config) -> + State = rebar_state:new([]), + rebar_hex_repos:update_auth_config(#{"foo" => <<200>>}, State), + rebar_hex_repos:update_auth_config(#{"foo" => <<200>>}, State). + organization_merging(_Config) -> Repo1 = #{name => <<"hexpm:repo-1">>, api_url => <<"repo-1/api">>},