Skip to content

Commit 84e0478

Browse files
Merge pull request #14277 from lukebakken/lukebakken/fix-popup-text-formatting
Fix error popup text display
2 parents a5106c6 + 5f5bf81 commit 84e0478

File tree

8 files changed

+15
-59
lines changed

8 files changed

+15
-59
lines changed

deps/rabbit/src/rabbit_definitions.erl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ format({shutdown, _} = Error) ->
710710
?LOG_DEBUG("Metadata store is unavailable: ~p", [Error]),
711711
rabbit_data_coercion:to_binary(
712712
rabbit_misc:format("Metadata store is unavailable. Please try again.", []));
713+
format(E) when is_binary(E) ->
714+
E;
713715
format(E) ->
714716
rabbit_data_coercion:to_binary(rabbit_misc:format("~tp", [E])).
715717

@@ -733,8 +735,8 @@ add_parameter(VHost, Param, Username) ->
733735
case Result of
734736
ok -> ok;
735737
{error_string, E} ->
736-
S = rabbit_misc:format(" (~ts/~ts/~ts)", [VHost, Comp, Key]),
737-
exit(rabbit_data_coercion:to_binary(rabbit_misc:escape_html_tags(E ++ S)))
738+
S = rabbit_misc:format(" (vhost: \"~ts\" / component: \"~ts\" / key: \"~ts\")", [VHost, Comp, Key]),
739+
exit(rabbit_data_coercion:to_utf8_binary(E ++ S))
738740
end.
739741

740742
add_global_parameter(Param, Username) ->
@@ -770,8 +772,8 @@ add_policy(VHost, Param, Username) ->
770772
maps:get('apply-to', Param, <<"all">>),
771773
Username) of
772774
ok -> ok;
773-
{error_string, E} -> S = rabbit_misc:format(" (~ts/~ts)", [VHost, Key]),
774-
exit(rabbit_data_coercion:to_binary(rabbit_misc:escape_html_tags(E ++ S)))
775+
{error_string, E} -> S = rabbit_misc:format(" (vhost: \"~ts\" key: \"~ts\")", [VHost, Key]),
776+
exit(rabbit_data_coercion:to_utf8_binary(E ++ S))
775777
end.
776778

777779
-spec add_vhost(map(), rabbit_types:username()) -> ok | no_return().

deps/rabbit_common/src/rabbit_misc.erl

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
-export([get_parent/0]).
7070
-export([store_proc_name/1, store_proc_name/2, get_proc_name/0]).
7171
-export([moving_average/4]).
72-
-export([escape_html_tags/1, b64decode_or_throw/1]).
72+
-export([b64decode_or_throw/1]).
7373
-export([get_env/3]).
7474
-export([get_channel_operation_timeout/0]).
7575
-export([random/1]).
@@ -1182,25 +1182,6 @@ moving_average(Time, HalfLife, Next, Current) ->
11821182
random(N) ->
11831183
rand:uniform(N).
11841184

1185-
-spec escape_html_tags(string()) -> binary().
1186-
1187-
escape_html_tags(S) ->
1188-
escape_html_tags(rabbit_data_coercion:to_list(S), []).
1189-
1190-
1191-
-spec escape_html_tags(string(), string()) -> binary().
1192-
1193-
escape_html_tags([], Acc) ->
1194-
rabbit_data_coercion:to_binary(lists:reverse(Acc));
1195-
escape_html_tags("<" ++ Rest, Acc) ->
1196-
escape_html_tags(Rest, lists:reverse("&lt;", Acc));
1197-
escape_html_tags(">" ++ Rest, Acc) ->
1198-
escape_html_tags(Rest, lists:reverse("&gt;", Acc));
1199-
escape_html_tags("&" ++ Rest, Acc) ->
1200-
escape_html_tags(Rest, lists:reverse("&amp;", Acc));
1201-
escape_html_tags([C | Rest], Acc) ->
1202-
escape_html_tags(Rest, [C | Acc]).
1203-
12041185
%% If the server we are talking to has non-standard net_ticktime, and
12051186
%% our connection lasts a while, we could get disconnected because of
12061187
%% a timeout unless we set our ticktime to be the same. So let's do

deps/rabbitmq_management/src/rabbit_mgmt_util.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,7 @@ with_vhost_and_props(Fun, ReqData, Context) ->
877877
bad_request(Error, ReqData1, Context)
878878
end;
879879
{error, Reason} ->
880-
bad_request(rabbit_mgmt_format:escape_html_tags(Reason),
881-
ReqData1, Context)
880+
bad_request(Reason, ReqData1, Context)
882881
end
883882
end.
884883

deps/rabbitmq_management/src/rabbit_mgmt_wm_healthchecks.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ to_json(ReqData, Context) ->
4848
{badrpc, Err} ->
4949
failure(rabbit_mgmt_format:print("~tp", Err), ReqData, Context);
5050
{error_string, Err} ->
51-
S = rabbit_mgmt_format:escape_html_tags(
52-
rabbit_data_coercion:to_list(rabbit_mgmt_format:print(Err))),
51+
S = rabbit_mgmt_format:print(Err),
5352
failure(S, ReqData, Context)
5453
end.
5554

deps/rabbitmq_management/src/rabbit_mgmt_wm_parameter.erl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ accept_content(ReqData0, Context = #context{user = User}) ->
6161
ok ->
6262
{true, ReqData, Context};
6363
{error_string, Reason} ->
64-
S = rabbit_mgmt_format:escape_html_tags(
65-
rabbit_data_coercion:to_list(Reason)),
66-
rabbit_mgmt_util:bad_request(
67-
rabbit_data_coercion:to_binary(S), ReqData, Context)
64+
rabbit_mgmt_util:bad_request(Reason, ReqData, Context)
6865
end
6966
end)
7067
end.

deps/rabbitmq_management/src/rabbit_mgmt_wm_policy.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ accept_content(ReqData0, Context = #context{user = #user{username = Username}})
6060
ok ->
6161
{true, ReqData, Context};
6262
{error_string, Reason} ->
63-
rabbit_mgmt_util:bad_request(
64-
rabbit_mgmt_format:escape_html_tags(Reason), ReqData, Context)
63+
rabbit_mgmt_util:bad_request(Reason, ReqData, Context)
6564
end
6665
end)
6766
end.

deps/rabbitmq_management_agent/src/rabbit_mgmt_format.erl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
-export([to_amqp_table/1, listener/1, web_context/1, properties/1, basic_properties/1]).
1616
-export([record/2, to_basic_properties/1]).
1717
-export([addr/1, port/1]).
18-
-export([format_nulls/1, escape_html_tags/1]).
18+
-export([format_nulls/1]).
1919
-export([print/2, print/1]).
2020

2121
-export([format_queue_stats/1, format_queue_basic_stats/1,
@@ -551,27 +551,6 @@ format_null_item([{_K, _V} | _T] = L) ->
551551
format_null_item(Value) ->
552552
Value.
553553

554-
555-
-spec escape_html_tags(string()) -> binary().
556-
557-
escape_html_tags(S) ->
558-
escape_html_tags(rabbit_data_coercion:to_list(S), []).
559-
560-
561-
-spec escape_html_tags(string(), string()) -> binary().
562-
563-
escape_html_tags([], Acc) ->
564-
rabbit_data_coercion:to_binary(lists:reverse(Acc));
565-
escape_html_tags("<" ++ Rest, Acc) ->
566-
escape_html_tags(Rest, lists:reverse("&lt;", Acc));
567-
escape_html_tags(">" ++ Rest, Acc) ->
568-
escape_html_tags(Rest, lists:reverse("&gt;", Acc));
569-
escape_html_tags("&" ++ Rest, Acc) ->
570-
escape_html_tags(Rest, lists:reverse("&amp;", Acc));
571-
escape_html_tags([C | Rest], Acc) ->
572-
escape_html_tags(Rest, [C | Acc]).
573-
574-
575554
-spec clean_consumer_details(proplists:proplist()) -> proplists:proplist().
576555
clean_consumer_details(Obj) ->
577556
case pget(consumer_details, Obj) of

deps/rabbitmq_web_dispatch/src/rabbit_web_dispatch_access_control.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ not_authorised(Reason, ReqData, Context) ->
275275

276276
halt_response(Code, Type, Reason, ReqData, Context) ->
277277
ReasonFormatted = format_reason(Reason),
278-
Json = #{<<"error">> => Type,
279-
<<"reason">> => ReasonFormatted},
278+
Json = #{error => Type,
279+
reason => ReasonFormatted},
280280
ReqData1 = cowboy_req:reply(Code,
281281
#{<<"content-type">> => <<"application/json">>},
282282
rabbit_json:encode(Json), ReqData),
@@ -288,7 +288,7 @@ not_authenticated(Reason, ReqData, Context, _AuthConfig) ->
288288
format_reason(Tuple) when is_tuple(Tuple) ->
289289
tuple(Tuple);
290290
format_reason(Binary) when is_binary(Binary) ->
291-
Binary;
291+
unicode:characters_to_binary(Binary);
292292
format_reason(Other) ->
293293
case is_string(Other) of
294294
true -> print("~ts", [Other]);

0 commit comments

Comments
 (0)