diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index 07e77992..c8230071 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -571,7 +571,7 @@ consult_env_config(State, Filename) -> {ok, Bin} -> unicode:characters_to_list(Bin) end, ReplacedStr = replace_env_vars(RawString), - case rebar_string:consult(unicode:characters_to_list(ReplacedStr)) of + case rebar_string:consult(ReplacedStr, utf8) of {error, Reason} -> throw(?PRV_ERROR({bad_term_file, Filename, Reason})); [Terms] -> diff --git a/src/rebar_string.erl b/src/rebar_string.erl index 56d6de3f..119923d6 100644 --- a/src/rebar_string.erl +++ b/src/rebar_string.erl @@ -6,7 +6,7 @@ %% Compatibility exports -export([join/2, split/2, lexemes/2, trim/1, trim/3, uppercase/1, lowercase/1, chr/2]). %% Util exports --export([consult/1]). +-export([consult/1, consult/2]). -ifdef(unicode_str). @@ -55,10 +55,18 @@ chr(Str, Char) -> string:chr(Str, Char). %% @doc %% Given a string or binary, parse it into a list of terms, ala file:consult/1 --spec consult(unicode:chardata()) -> {error, term()} | [term()]. -consult(Str) -> +-spec consult(unicode:chardata(), epp:source_encoding() | none) -> {error, term()} | [term()]. +consult(Str, none) -> + consult(Str, epp:default_encoding()); +consult(Bin, latin1) when is_binary(Bin) -> + consult([], binary_to_list(Bin), []); +consult(Str, _) -> consult([], unicode:characters_to_list(Str), []). +%% Backward compatibility for plugins. +-spec consult(unicode:chardata()) -> {error, term()} | [term()]. +consult(Str) -> consult(Str, utf8). + consult(Cont, Str, Acc) -> case erl_scan:tokens(Cont, Str, 0) of {done, Result, Remaining} -> diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index 7266f44e..22e3b772 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -59,7 +59,7 @@ list_templates(State) -> %% Expand a single template's value list_template(Files, {Name, Type, File}, State) -> - case rebar_string:consult(binary_to_list(load_file(Files, Type, File))) of + case consult_template(Files, Type, File) of {error, Reason} -> {error, {consult, File, Reason}}; TemplateTerms -> @@ -158,7 +158,7 @@ drop_var_docs([{K,V}|Rest]) -> [{K,V} | drop_var_docs(Rest)]. %% Load the template index, resolve all variables, and then execute %% the template. create({Template, Type, File}, Files, UserVars, Force, State) -> - TemplateTerms = rebar_string:consult(binary_to_list(load_file(Files, Type, File))), + TemplateTerms = consult_template(Files, Type, File), Vars = drop_var_docs(override_vars(UserVars, get_template_vars(TemplateTerms, State))), maybe_warn_about_name(Vars), TemplateCwd = filename:dirname(File), @@ -439,3 +439,7 @@ render(Bin, Context) -> [{key_type, atom}, {escape_fun, fun(X) -> X end}] % disable HTML-style escaping ). + +consult_template(Files, Type, File) -> + TemplateBin = load_file(Files, Type, File), + rebar_string:consult(TemplateBin, epp:read_encoding_from_binary(TemplateBin)).