Skip to content

Commit

Permalink
Ensure provider hook calls don't crash because of invalid command lin…
Browse files Browse the repository at this point in the history
…e arguments

Normally the CLI arguments are intended for the provider which is called
directly. When these are forwarded to other providers through hooks
things might break.
  • Loading branch information
tolbrino committed Jun 2, 2020
1 parent 1604e4f commit 1d8db94
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/rebar_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ run_all_hooks(Dir, Type, Command, Providers, State) ->
run_hooks(Dir, Type, Command, rebar_state:opts(State), State).

run_project_and_app_hooks(Dir, Type, Command, Providers, State) ->
ProjectApps = rebar_state:project_apps(State),
[rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) || AppInfo <- ProjectApps],
run_all_hooks(Dir, Type, Command, Providers, State).
% The command_args which the original invocation of rebar received are most
% likely not applicable to the hooks which will be called. Therefore, the
% args are discarded to not crash provider hook invocations.
State1 = rebar_state:command_args(State, []),
ProjectApps = rebar_state:project_apps(State1),
[rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State1) || AppInfo <- ProjectApps],
run_all_hooks(Dir, Type, Command, Providers, State1).

run_provider_hooks(Dir, Type, Command, Providers, Opts, State) ->
case rebar_opts:get(Opts, provider_hooks, []) of
Expand Down

0 comments on commit 1d8db94

Please sign in to comment.