@@ -157,7 +157,7 @@ def coerce_hash!(input)
157157 in Hash | nil => coerced
158158 coerced
159159 else
160- message = "Expected a #{ Hash } or #{ VitableConnect ::Internal ::Type ::BaseModel } , got #{ data . inspect } "
160+ message = "Expected a #{ Hash } or #{ VitableConnect ::Internal ::Type ::BaseModel } , got #{ input . inspect } "
161161 raise ArgumentError . new ( message )
162162 end
163163 end
@@ -237,6 +237,11 @@ def dig(data, pick, &blk)
237237 end
238238 end
239239
240+ # @type [Regexp]
241+ #
242+ # https://www.rfc-editor.org/rfc/rfc3986.html#section-3.3
243+ RFC_3986_NOT_PCHARS = /[^A-Za-z0-9\- ._~!$&'()*+,;=:@]+/
244+
240245 class << self
241246 # @api private
242247 #
@@ -247,6 +252,15 @@ def uri_origin(uri)
247252 "#{ uri . scheme } ://#{ uri . host } #{ ":#{ uri . port } " unless uri . port == uri . default_port } "
248253 end
249254
255+ # @api private
256+ #
257+ # @param path [String, Integer]
258+ #
259+ # @return [String]
260+ def encode_path ( path )
261+ path . to_s . gsub ( VitableConnect ::Internal ::Util ::RFC_3986_NOT_PCHARS ) { ERB ::Util . url_encode ( _1 ) }
262+ end
263+
250264 # @api private
251265 #
252266 # @param path [String, Array<String>]
@@ -259,7 +273,7 @@ def interpolate_path(path)
259273 in [ ]
260274 ""
261275 in [ String => p , *interpolations ]
262- encoded = interpolations . map { ERB :: Util . url_encode ( _1 ) }
276+ encoded = interpolations . map { encode_path ( _1 ) }
263277 format ( p , *encoded )
264278 end
265279 end
@@ -576,10 +590,10 @@ def encode_query_params(query)
576590
577591 case val
578592 in VitableConnect ::FilePart unless val . filename . nil?
579- filename = ERB :: Util . url_encode ( val . filename )
593+ filename = encode_path ( val . filename )
580594 y << "; filename=\" #{ filename } \" "
581595 in Pathname | IO
582- filename = ERB :: Util . url_encode ( ::File . basename ( val . to_path ) )
596+ filename = encode_path ( ::File . basename ( val . to_path ) )
583597 y << "; filename=\" #{ filename } \" "
584598 else
585599 end
0 commit comments