Skip to content

Commit

Permalink
fix(include_dirs): Don't truncation include_dirs dir path name.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed Dec 28, 2021
1 parent b6baf9c commit 7d03687
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/hocon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ load(Filename0) ->
-spec(load(file:filename(), opts()) -> {ok, config()} | {error, term()}).
load(Filename0, Opts) ->
Filename = hocon_util:real_file_name(filename:absname(Filename0)),
IncludeDirs = [filename:dirname(Dir) || Dir <- maps:get(include_dirs, Opts, [])],
IncludeDirs = maps:get(include_dirs, Opts, []),
CtxList = [{path, '$root'}, {filename, Filename}, {include_dirs, IncludeDirs}],
Ctx = hocon_util:stack_multiple_push(CtxList, #{}),
try
Expand Down Expand Up @@ -93,7 +93,7 @@ binary(Binary) ->

binary(Binary, Opts) ->
try
IncludeDirs = [filename:dirname(Dir) || Dir <-maps:get(include_dirs, Opts, [])],
IncludeDirs = maps:get(include_dirs, Opts, []),
CtxList = [{path, '$root'}, {filename, undefined}, {include_dirs, IncludeDirs}],
Ctx = hocon_util:stack_multiple_push(CtxList, #{}),
Map = transform(do_binary(Binary, Ctx), Opts),
Expand Down
7 changes: 5 additions & 2 deletions test/hocon_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,12 @@ include_dirs_test() ->
#{<<"cookie">> => <<"emqxsecretcookie">>,
<<"data_dir">> => <<"platform_data_dir">>,
<<"name">> => <<"[email protected]">>}},
Opts = #{include_dirs => ["test/data/", "sample-configs/"]},
{ok, Map} = hocon:load("etc/include-dir.conf", Opts),
Opts = #{include_dirs => ["test/data", "sample-configs/", "etc/"]},
Filename = "etc/include-dir.conf",
{ok, Map} = hocon:load(Filename, Opts),
?assertEqual(Expect, Map),
{ok, Map2} = hocon:binary(hocon_token:read(Filename), Opts),
?assertEqual(Expect, Map2),
{error, Reason} = hocon:load("etc/include-dir-enoent.conf", Opts),
?assertEqual({enoent, <<"not-exist.conf">>}, Reason),
ok.
Expand Down

0 comments on commit 7d03687

Please sign in to comment.