Skip to content

Commit 50bcd88

Browse files
ansdmichaelklishin
authored andcommitted
Delete rabbit_uri
Since #13242 updated Cowlib to v2.14.0, this commit deletes rabbit_uri as written in the comments of rabbit_uri.erl: ``` This file is a partial copy of https://github.com/ninenines/cowlib/blob/optimise-urldecode/src/cow_uri.erl We use this copy because: 1. uri_string:unquote/1 is lax: It doesn't validate that characters that are required to be percent encoded are indeed percent encoded. In RabbitMQ, we want to enforce that proper percent encoding is done by AMQP clients. 2. uri_string:unquote/1 and cow_uri:urldecode/1 in cowlib v2.13.0 are both slow because they allocate a new binary for the common case where no character was percent encoded. When a new cowlib version is released, we should make app rabbit depend on app cowlib calling cow_uri:urldecode/1 and delete this file (rabbit_uri.erl). ```
1 parent 9dc86d2 commit 50bcd88

File tree

5 files changed

+16
-170
lines changed

5 files changed

+16
-170
lines changed

deps/rabbit/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ endef
129129
LOCAL_DEPS = sasl os_mon inets compiler public_key crypto ssl syntax_tools xmerl
130130

131131
BUILD_DEPS = rabbitmq_cli
132-
DEPS = ranch rabbit_common amqp10_common rabbitmq_prelaunch ra sysmon_handler stdout_formatter recon redbug observer_cli osiris syslog systemd seshat horus khepri khepri_mnesia_migration cuttlefish gen_batch_server
132+
DEPS = ranch cowlib rabbit_common amqp10_common rabbitmq_prelaunch ra sysmon_handler stdout_formatter recon redbug observer_cli osiris syslog systemd seshat horus khepri khepri_mnesia_migration cuttlefish gen_batch_server
133133
TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers meck proper amqp_client rabbitmq_amqp_client rabbitmq_amqp1_0
134134

135135
# We pin a version of Horus even if we don't use it directly (it is a

deps/rabbit/src/rabbit_amqp_management.erl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ handle_http_req(<<"GET">>,
8080
_User,
8181
_ConnPid,
8282
PermCaches) ->
83-
QNameBin = rabbit_uri:urldecode(QNameBinQuoted),
83+
QNameBin = cow_uri:urldecode(QNameBinQuoted),
8484
QName = queue_resource(Vhost, QNameBin),
8585
case rabbit_amqqueue:with(
8686
QName,
@@ -110,7 +110,7 @@ handle_http_req(HttpMethod = <<"PUT">>,
110110
exclusive := Exclusive,
111111
arguments := QArgs0
112112
} = decode_queue(ReqPayload),
113-
QNameBin = rabbit_uri:urldecode(QNameBinQuoted),
113+
QNameBin = cow_uri:urldecode(QNameBinQuoted),
114114
Owner = case Exclusive of
115115
true -> ConnPid;
116116
false -> none
@@ -190,7 +190,7 @@ handle_http_req(<<"PUT">>,
190190
User = #user{username = Username},
191191
_ConnPid,
192192
{PermCache0, TopicPermCache}) ->
193-
XNameBin = rabbit_uri:urldecode(XNameBinQuoted),
193+
XNameBin = cow_uri:urldecode(XNameBinQuoted),
194194
#{type := XTypeBin,
195195
durable := Durable,
196196
auto_delete := AutoDelete,
@@ -240,7 +240,7 @@ handle_http_req(<<"DELETE">>,
240240
User,
241241
ConnPid,
242242
{PermCache0, TopicPermCache}) ->
243-
QNameBin = rabbit_uri:urldecode(QNameBinQuoted),
243+
QNameBin = cow_uri:urldecode(QNameBinQuoted),
244244
QName = queue_resource(Vhost, QNameBin),
245245
PermCache = check_resource_access(QName, read, User, PermCache0),
246246
try rabbit_amqqueue:with_exclusive_access_or_die(
@@ -270,7 +270,7 @@ handle_http_req(<<"DELETE">>,
270270
User = #user{username = Username},
271271
ConnPid,
272272
{PermCache0, TopicPermCache}) ->
273-
QNameBin = rabbit_uri:urldecode(QNameBinQuoted),
273+
QNameBin = cow_uri:urldecode(QNameBinQuoted),
274274
QName = queue_resource(Vhost, QNameBin),
275275
ok = prohibit_cr_lf(QNameBin),
276276
PermCache = check_resource_access(QName, configure, User, PermCache0),
@@ -290,7 +290,7 @@ handle_http_req(<<"DELETE">>,
290290
User = #user{username = Username},
291291
_ConnPid,
292292
{PermCache0, TopicPermCache}) ->
293-
XNameBin = rabbit_uri:urldecode(XNameBinQuoted),
293+
XNameBin = cow_uri:urldecode(XNameBinQuoted),
294294
XName = exchange_resource(Vhost, XNameBin),
295295
ok = prohibit_cr_lf(XNameBin),
296296
ok = prohibit_default_exchange(XName),
@@ -630,9 +630,9 @@ decode_binding_path_segment(Segment) ->
630630
end,
631631
case re:run(Segment, MP, [{capture, all_but_first, binary}]) of
632632
{match, [SrcQ, <<DstKindChar>>, DstQ, KeyQ, ArgsHash]} ->
633-
Src = rabbit_uri:urldecode(SrcQ),
634-
Dst = rabbit_uri:urldecode(DstQ),
635-
Key = rabbit_uri:urldecode(KeyQ),
633+
Src = cow_uri:urldecode(SrcQ),
634+
Dst = cow_uri:urldecode(DstQ),
635+
Key = cow_uri:urldecode(KeyQ),
636636
DstKind = destination_char_to_kind(DstKindChar),
637637
{Src, DstKind, Dst, Key, ArgsHash};
638638
nomatch ->

deps/rabbit/src/rabbit_amqp_session.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ ensure_source(Source = #'v1_0.source'{address = Address,
26992699
{utf8, <<"/queues/", QNameBinQuoted/binary>>} ->
27002700
%% The only possible v2 source address format is:
27012701
%% /queues/:queue
2702-
try rabbit_uri:urldecode(QNameBinQuoted) of
2702+
try cow_uri:urldecode(QNameBinQuoted) of
27032703
QNameBin ->
27042704
QName = queue_resource(Vhost, QNameBin),
27052705
ok = exit_if_absent(QName),
@@ -2907,11 +2907,11 @@ parse_target_v2_string0(<<"/exchanges/", Rest/binary>>) ->
29072907
[<<"amq.default">> | _] ->
29082908
{error, bad_address};
29092909
[XNameBinQuoted] ->
2910-
XNameBin = rabbit_uri:urldecode(XNameBinQuoted),
2910+
XNameBin = cow_uri:urldecode(XNameBinQuoted),
29112911
{ok, XNameBin, <<>>, undefined};
29122912
[XNameBinQuoted, RKeyQuoted] ->
2913-
XNameBin = rabbit_uri:urldecode(XNameBinQuoted),
2914-
RKey = rabbit_uri:urldecode(RKeyQuoted),
2913+
XNameBin = cow_uri:urldecode(XNameBinQuoted),
2914+
RKey = cow_uri:urldecode(RKeyQuoted),
29152915
{ok, XNameBin, RKey, undefined};
29162916
_ ->
29172917
{error, bad_address}
@@ -2920,7 +2920,7 @@ parse_target_v2_string0(<<"/queues/">>) ->
29202920
%% empty queue name is invalid
29212921
{error, bad_address};
29222922
parse_target_v2_string0(<<"/queues/", QNameBinQuoted/binary>>) ->
2923-
QNameBin = rabbit_uri:urldecode(QNameBinQuoted),
2923+
QNameBin = cow_uri:urldecode(QNameBinQuoted),
29242924
{ok, ?DEFAULT_EXCHANGE_NAME, QNameBin, QNameBin};
29252925
parse_target_v2_string0(_) ->
29262926
{error, bad_address}.

deps/rabbit/src/rabbit_uri.erl

Lines changed: 0 additions & 154 deletions
This file was deleted.

deps/rabbitmq_mqtt/src/mc_mqtt.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ convert_from(mc_amqp, Sections, Env) ->
9292
MqttX:(byte_size(MqttX))/binary,
9393
"/",
9494
RoutingKeyQuoted/binary>> ->
95-
try rabbit_uri:urldecode(RoutingKeyQuoted) of
95+
try cow_uri:urldecode(RoutingKeyQuoted) of
9696
RoutingKey ->
9797
MqttTopic = rabbit_mqtt_util:amqp_to_mqtt(RoutingKey),
9898
#{'Response-Topic' => MqttTopic}

0 commit comments

Comments
 (0)