1
1
# encoding: utf-8
2
2
3
- require "cgi"
3
+ if RUBY_VERSION < "3.5"
4
+ require "cgi/util"
5
+ else
6
+ require "cgi/escape"
7
+ end
4
8
require "uri"
5
9
6
10
module AMQ
@@ -43,28 +47,33 @@ def self.parse(connection_string)
43
47
end
44
48
45
49
if uri . query
46
- query_params = CGI ::parse ( uri . query )
47
-
48
- normalized_query_params = Hash [ query_params . map { |param , value | [ param , value . one? ? value . first : value ] } ]
50
+ query_params = Hash . new { |hash , key | hash [ key ] = [ ] }
51
+ ::URI . decode_www_form ( uri . query ) . each do |key , value |
52
+ query_params [ key ] << value
53
+ end
54
+ query_params . each do |key , value |
55
+ query_params [ key ] = value . one? ? value . first : value
56
+ end
57
+ query_params . default = nil
49
58
50
- opts [ :heartbeat ] = normalized_query_params [ "heartbeat" ] . to_i
51
- opts [ :connection_timeout ] = normalized_query_params [ "connection_timeout" ] . to_i
52
- opts [ :channel_max ] = normalized_query_params [ "channel_max" ] . to_i
53
- opts [ :auth_mechanism ] = normalized_query_params [ "auth_mechanism" ]
59
+ opts [ :heartbeat ] = query_params [ "heartbeat" ] . to_i
60
+ opts [ :connection_timeout ] = query_params [ "connection_timeout" ] . to_i
61
+ opts [ :channel_max ] = query_params [ "channel_max" ] . to_i
62
+ opts [ :auth_mechanism ] = query_params [ "auth_mechanism" ]
54
63
55
64
%w( cacertfile certfile keyfile ) . each do |tls_option |
56
- if normalized_query_params [ tls_option ] && uri . scheme == "amqp"
65
+ if query_params [ tls_option ] && uri . scheme == "amqp"
57
66
raise ArgumentError . new ( "The option '#{ tls_option } ' can only be used in URIs that use amqps schema" )
58
67
else
59
- opts [ tls_option . to_sym ] = normalized_query_params [ tls_option ]
68
+ opts [ tls_option . to_sym ] = query_params [ tls_option ]
60
69
end
61
70
end
62
71
63
72
%w( verify fail_if_no_peer_cert ) . each do |tls_option |
64
- if normalized_query_params [ tls_option ] && uri . scheme == "amqp"
73
+ if query_params [ tls_option ] && uri . scheme == "amqp"
65
74
raise ArgumentError . new ( "The option '#{ tls_option } ' can only be used in URIs that use amqps schema" )
66
75
else
67
- opts [ tls_option . to_sym ] = as_boolean ( normalized_query_params [ tls_option ] )
76
+ opts [ tls_option . to_sym ] = as_boolean ( query_params [ tls_option ] )
68
77
end
69
78
end
70
79
end
@@ -80,7 +89,7 @@ def self.parse_amqp_url(s)
80
89
# Implementation
81
90
#
82
91
83
- # Normalizes values returned by CGI.parse .
92
+ # Normalizes values returned by URI.decode_www_form .
84
93
# @private
85
94
def self . as_boolean ( val )
86
95
case val
0 commit comments