Skip to content

Commit be80470

Browse files
[DOC] Common rdoc (#52)
1 parent 8b4f0e2 commit be80470

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/uri/common.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ def self.regexp(schemes = nil)# :nodoc:
330330
# and then to encoding +enc+.
331331
#
332332
# 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>).
333335
def self.encode_www_form_component(str, enc=nil)
334336
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc)
335337
end
@@ -362,20 +364,18 @@ def self.encode_www_form_component(str, enc=nil)
362364
# URI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A')
363365
# # => "Here are some punctuation characters: ,;?:"
364366
#
367+
# Related: URI.decode_uri_component (preserves <tt>'+'</tt>).
365368
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
366369
_decode_uri_component(/\+|%\h\h/, str, enc)
367370
end
368371

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>).
372374
def self.encode_uri_component(str, enc=nil)
373375
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCURICOMP_, str, enc)
374376
end
375377

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.
379379
def self.decode_uri_component(str, enc=Encoding::UTF_8)
380380
_decode_uri_component(/%\h\h/, str, enc)
381381
end
@@ -419,6 +419,12 @@ def self._decode_uri_component(regexp, str, enc)
419419
# URI.encode_www_form({foo: 0, bar: 1, baz: 2})
420420
# # => "foo=0&bar=1&baz=2"
421421
#
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+
#
422428
# When +enum+ is Array-like, each element +ele+ is converted to a field:
423429
#
424430
# - If +ele+ is an array of two or more elements,

0 commit comments

Comments
 (0)