@@ -330,6 +330,8 @@ def self.regexp(schemes = nil)# :nodoc:
330
330
# and then to encoding +enc+.
331
331
#
332
332
# In either case, the returned string has forced encoding Encoding::US_ASCII.
333
+ #
334
+ # Related: URI.encode_uri_component (encodes <tt>' '</tt> as <tt>'%20'</tt>).
333
335
def self . encode_www_form_component ( str , enc = nil )
334
336
_encode_uri_component ( /[^*\- .0-9A-Z_a-z]/ , TBLENCWWWCOMP_ , str , enc )
335
337
end
@@ -362,20 +364,18 @@ def self.encode_www_form_component(str, enc=nil)
362
364
# URI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A')
363
365
# # => "Here are some punctuation characters: ,;?:"
364
366
#
367
+ # Related: URI.decode_uri_component (preserves <tt>'+'</tt>).
365
368
def self . decode_www_form_component ( str , enc = Encoding ::UTF_8 )
366
369
_decode_uri_component ( /\+ |%\h \h / , str , enc )
367
370
end
368
371
369
- # Encodes +str+ using URL encoding
370
- #
371
- # This encodes SP to %20 instead of +.
372
+ # Like URI.encode_www_form_component, except that <tt>' '</tt> (space)
373
+ # is encoded as <tt>'%20'</tt> (instead of <tt>'+'</tt>).
372
374
def self . encode_uri_component ( str , enc = nil )
373
375
_encode_uri_component ( /[^*\- .0-9A-Z_a-z]/ , TBLENCURICOMP_ , str , enc )
374
376
end
375
377
376
- # Decodes given +str+ of URL-encoded data.
377
- #
378
- # This does not decode + to SP.
378
+ # Like URI.decode_www_form_component, except that <tt>'+'</tt> is preserved.
379
379
def self . decode_uri_component ( str , enc = Encoding ::UTF_8 )
380
380
_decode_uri_component ( /%\h \h / , str , enc )
381
381
end
@@ -419,6 +419,12 @@ def self._decode_uri_component(regexp, str, enc)
419
419
# URI.encode_www_form({foo: 0, bar: 1, baz: 2})
420
420
# # => "foo=0&bar=1&baz=2"
421
421
#
422
+ # The returned string is formed using method URI.encode_www_form_component,
423
+ # which converts certain characters:
424
+ #
425
+ # URI.encode_www_form('f#o': '/', 'b-r': '$')
426
+ # # => "f%23o=%2F&b-r=%24"
427
+ #
422
428
# When +enum+ is Array-like, each element +ele+ is converted to a field:
423
429
#
424
430
# - If +ele+ is an array of two or more elements,
0 commit comments