Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] Enhanced RDoc for common methods #50

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,13 @@ def self.parse(uri)
RFC3986_PARSER.parse(uri)
end

# Merges the given URI strings +str+
# per {RFC 2396}[https://www.rfc-editor.org/rfc/rfc2396.html].
#
# == Synopsis
#
# URI::join(str[, str, ...])
#
# == Args
#
# +str+::
# String(s) to work with, will be converted to RFC3986 URIs before merging.
#
# == Description
# Each string in +str+ is converted to an
# {RFC3986 URI}[https://www.rfc-editor.org/rfc/rfc3986.html] before being merged.
#
# Joins URIs.
#
# == Usage
#
# require 'uri'
# Examples:
#
# URI.join("http://example.com/","main.rbx")
# # => #<URI::HTTP http://example.com/main.rbx>
Expand Down Expand Up @@ -246,7 +236,7 @@ def self.join(*str)
# URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")
# # => ["http://foo.example.com/bla", "mailto:test@example.com"]
#
def self.extract(str, schemes = nil, &block)
def self.extract(str, schemes = nil, &block) # :nodoc:
warn "URI.extract is obsolete", uplevel: 1 if $VERBOSE
DEFAULT_PARSER.extract(str, schemes, &block)
end
Expand Down Expand Up @@ -283,7 +273,7 @@ def self.extract(str, schemes = nil, &block)
# p $&
# end
#
def self.regexp(schemes = nil)
def self.regexp(schemes = nil)# :nodoc:
warn "URI.regexp is obsolete", uplevel: 1 if $VERBOSE
DEFAULT_PARSER.make_regexp(schemes)
end
Expand Down Expand Up @@ -340,16 +330,38 @@ def self.regexp(schemes = nil)
# and then to encoding +enc+.
#
# In either case, the returned string has forced encoding Encoding::US_ASCII.
#
def self.encode_www_form_component(str, enc=nil)
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc)
end

# Decodes given +str+ of URL-encoded form data.
# 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 <tt>'*'</tt>, <tt>'.'</tt>, <tt>'-'</tt>, and <tt>'_'</tt>.
# - Character in ranges <tt>'a'..'z'</tt>, <tt>'A'..'Z'</tt>,
# and <tt>'0'..'9'</tt>.
#
# Example:
#
# URI.decode_www_form_component('*.-_azAZ09')
# # => "*.-_azAZ09"
#
# - Converts:
#
# - Character <tt>'+'</tt> to character <tt>' '</tt>.
# - Each "percent notation" to an ASCII character.
#
# Example:
#
# This decodes + to SP.
# URI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A')
# # => "Here are some punctuation characters: ,;?:"
#
# See URI.encode_www_form_component, URI.decode_www_form.
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
_decode_uri_component(/\+|%\h\h/, str, enc)
end
Expand Down