Skip to content

Commit 67fa17a

Browse files
Merge pull request #17010 from rabbitmq/mergify/bp/v4.3.x/pr-16958
Adopt `rabbit_re` in more places (backport #16958)
2 parents 0d9854d + 41ca1ac commit 67fa17a

4 files changed

Lines changed: 18 additions & 23 deletions

File tree

deps/rabbit/src/rabbit_credential_validator_password_regexp.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ validate(Username, Password) ->
3434
-spec validate(rabbit_types:username(), rabbit_types:password(), string()) -> 'ok' | {'error', string(), [any()]}.
3535

3636
validate(_Username, Password, Pattern) ->
37-
case re:run(rabbit_data_coercion:to_list(Password), Pattern) of
38-
{match, _} -> ok;
39-
nomatch -> {error, "provided password does not match the validator regular expression"}
37+
case rabbit_re:run(rabbit_data_coercion:to_list(Password), Pattern) of
38+
match -> ok;
39+
nomatch -> {error, "provided password does not match the validator regular expression"}
4040
end.

deps/rabbit/src/rabbit_db_vhost_defaults.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ list_limits(VHost) ->
7171
Match = lists:search(
7272
fun({_, Ss}) ->
7373
RE = proplists:get_value(<<"pattern">>, Ss, ".*"),
74-
re:run(VHost, RE, [{capture, none}]) =:= match
74+
rabbit_re:matches(VHost, RE)
7575
end,
7676
VHostLimits
7777
),
@@ -91,8 +91,8 @@ list_operator_policies(VHost) ->
9191
lists:filtermap(
9292
fun({PolicyName, Ss}) ->
9393
RE = proplists:get_value(<<"vhost_pattern">>, Ss, ".*"),
94-
case re:run(VHost, RE, [{capture, none}]) of
95-
match ->
94+
case rabbit_re:matches(VHost, RE) of
95+
true ->
9696
QPattern = proplists:get_value(<<"queue_pattern">>, Ss, <<".*">>),
9797
ApplyTo = proplists:get_value(<<"apply_to">>, Ss, <<"all">>),
9898
Ss1 = proplists:delete(<<"queue_pattern">>, Ss),
@@ -118,8 +118,8 @@ list_users(VHost) ->
118118
lists:filtermap(
119119
fun({Username, Ss}) ->
120120
RE = proplists:get_value(<<"vhost_pattern">>, Ss, ".*"),
121-
case re:run(VHost, RE, [{capture, none}]) of
122-
match ->
121+
case rabbit_re:matches(VHost, RE) of
122+
true ->
123123
C = rabbit_data_coercion:to_binary(
124124
proplists:get_value(<<"configure">>, Ss, <<".*">>)
125125
),

deps/rabbitmq_auth_backend_ldap/src/rabbit_auth_backend_ldap.erl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,9 @@ safe_eval(_F, _, {error, _}) -> false;
428428
safe_eval(F, V1, V2) -> F(V1, V2).
429429

430430
do_match(S1, S2) ->
431-
case re:run(S1, S2) of
432-
{match, _} ->
433-
log_match(S1, S2, R = true),
434-
R;
435-
nomatch ->
436-
log_match(S1, S2, R = false),
437-
R
438-
end.
431+
R = rabbit_re:matches(S1, S2),
432+
log_match(S1, S2, R),
433+
R.
439434

440435
%% In some cases when fetching regular expressions, LDAP evalution()
441436
%% returns a list of strings, so we need to wrap guards around that.
@@ -444,23 +439,23 @@ do_match_multi(S1, []) ->
444439
log_match(S1, [], R = false),
445440
R;
446441
do_match_multi(S1 = [H1|_], [H2|Tail]) when is_list(H2) and not is_list(H1) ->
447-
case re:run(S1, H2) of
448-
{match, _} ->
442+
case rabbit_re:matches(S1, H2) of
443+
true ->
449444
log_match(S1, H2, R = true),
450445
R;
451-
_ ->
446+
false ->
452447
log_match(S1,H2, false),
453448
do_match_multi(S1, Tail)
454449
end;
455450
do_match_multi([], S2) ->
456451
log_match([], S2, R = false),
457452
R;
458453
do_match_multi([H1|Tail], S2 = [H2|_] ) when is_list(H1) and not is_list(H2) ->
459-
case re:run(H1, S2) of
460-
{match, _} ->
454+
case rabbit_re:matches(H1, S2) of
455+
true ->
461456
log_match(H1, S2, R = true),
462457
R;
463-
_ ->
458+
false ->
464459
log_match(H1, S2, false),
465460
do_match_multi(Tail, S2)
466461
end;

deps/rabbitmq_management_agent/src/rabbit_mgmt_metrics_collector.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ maybe_insert_entry_ops(Name, Pattern, Table, Id, Incr, Entry, Ops, Policies) ->
631631
needs_filtering_out(_, undefined) ->
632632
false;
633633
needs_filtering_out(#resource{name = Name}, Pattern) ->
634-
match == re:run(Name, Pattern, [{capture, none}]).
634+
rabbit_re:matches(Name, Pattern).
635635

636636
insert_entry_ops(Table, Id, Incr, Entry, Ops, Policies) ->
637637
lists:foldl(fun({Size, Interval}, Acc) ->

0 commit comments

Comments
 (0)