diff options
| author | zverok <zverok.offline@gmail.com> | 2025-12-23 22:17:12 +0200 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-12-24 11:21:11 +0900 |
| commit | 9154d72a3e342b6bf101d0d1e3c8bbd0feee3422 (patch) | |
| tree | 1509d29b8f9d533c351aa98ec81befee0af54fe0 /lib | |
| parent | 10a68210b4c96ab2de21357907627e1fb34ce000 (diff) | |
Improve CGI.escape* docs
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/cgi/escape.rb | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/cgi/escape.rb b/lib/cgi/escape.rb index 6d84773fdd..555d24a5da 100644 --- a/lib/cgi/escape.rb +++ b/lib/cgi/escape.rb @@ -1,20 +1,28 @@ # frozen_string_literal: true -# :stopdoc +# Since Ruby 4.0, \CGI is a small holder for various escaping methods, included from CGI::Escape +# +# require 'cgi/escape' +# +# CGI.escape("Ruby programming language") +# #=> "Ruby+programming+language" +# CGI.escapeURIComponent("Ruby programming language") +# #=> "Ruby%20programming%20language" +# +# See CGI::Escape module for methods list and their description. class CGI module Escape; end include Escape extend Escape module EscapeExt; end # :nodoc: end -# :startdoc: -# Escape/unescape for CGI, HTML, URI. +# Web-related escape/unescape functionality. module CGI::Escape @@accept_charset = Encoding::UTF_8 unless defined?(@@accept_charset) # URL-encode a string into application/x-www-form-urlencoded. - # Space characters (+" "+) are encoded with plus signs (+"+"+) + # Space characters (<tt>" "</tt>) are encoded with plus signs (<tt>"+"</tt>) # url_encoded_string = CGI.escape("'Stop!' said Fred") # # => "%27Stop%21%27+said+Fred" def escape(string) @@ -41,7 +49,7 @@ module CGI::Escape end # URL-encode a string following RFC 3986 - # Space characters (+" "+) are encoded with (+"%20"+) + # Space characters (<tt>" "</tt>) are encoded with (<tt>"%20"</tt>) # url_encoded_string = CGI.escapeURIComponent("'Stop!' said Fred") # # => "%27Stop%21%27%20said%20Fred" def escapeURIComponent(string) @@ -69,7 +77,7 @@ module CGI::Escape alias unescape_uri_component unescapeURIComponent # The set of special characters and their escaped values - TABLE_FOR_ESCAPE_HTML__ = { + TABLE_FOR_ESCAPE_HTML__ = { # :nodoc: "'" => ''', '&' => '&', '"' => '"', @@ -77,7 +85,7 @@ module CGI::Escape '>' => '>', } - # Escape special characters in HTML, namely '&\"<> + # \Escape special characters in HTML, namely <tt>'&\"<></tt> # CGI.escapeHTML('Usage: foo "bar" <baz>') # # => "Usage: foo "bar" <baz>" def escapeHTML(string) @@ -160,11 +168,9 @@ module CGI::Escape string.force_encoding enc end - # Synonym for CGI.escapeHTML(str) alias escape_html escapeHTML alias h escapeHTML - # Synonym for CGI.unescapeHTML(str) alias unescape_html unescapeHTML # TruffleRuby runs the pure-Ruby variant faster, do not use the C extension there @@ -175,7 +181,7 @@ module CGI::Escape end end - # Escape only the tags of certain HTML elements in +string+. + # \Escape only the tags of certain HTML elements in +string+. # # Takes an element or elements or array of elements. Each element # is specified by the name of the element, without angle brackets. @@ -199,7 +205,7 @@ module CGI::Escape end end - # Undo escaping such as that done by CGI.escapeElement() + # Undo escaping such as that done by CGI.escapeElement # # print CGI.unescapeElement( # CGI.escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG") @@ -219,10 +225,8 @@ module CGI::Escape end end - # Synonym for CGI.escapeElement(str) alias escape_element escapeElement - # Synonym for CGI.unescapeElement(str) alias unescape_element unescapeElement end |
