Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
URI.decode_www_form_component
(::String str, ?::encoding enc) -> ::String
decode_www_form_component(str, enc=Encoding::UTF_8)
lib/uri/common.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/uri/common.rb, line 430
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
_decode_uri_component(/\+|%\h\h/, str, enc)
end
Returns a string decoded from the given URL-encoded string str.
The given string is first encoded as Encoding::ASCII-8BIT (using String#b), then decoded (as below), and finally force-encoded to the given encoding enc.
The returned string:
-
Preserves:
-
Characters
'*','.','-', and'_'. -
Character in ranges
'a'..'z','A'..'Z', and'0'..'9'.
Example:
ExampleURI.decode_www_form_component('*.-_azAZ09') # => "*.-_azAZ09"
-
-
Converts:
-
Character
'+'to character' '. -
Each “percent notation” to an ASCII character.
Example:
ExampleURI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A') # => "Here are some punctuation characters: ,;?:"
-
Related: URI.decode_uri_component (preserves '+').
See also
.decode_www_form
._encode_uri_component
.decode_uri_component
.encode_uri_component
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0