lib/ronin/formatting/extensions/http/string.rb in ronin-0.1.3 vs lib/ronin/formatting/extensions/http/string.rb in ronin-0.1.4
- old
+ new
@@ -19,10 +19,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#++
#
+require 'ronin/formatting/extensions/text'
+
require 'uri'
require 'cgi'
class String
@@ -62,8 +64,18 @@
# "sweet+%26+sour".uri_unescape
# # => "sweet & sour"
#
def uri_unescape
CGI.unescape(self)
+ end
+
+ #
+ # Returns the HTTP hexidecimal encoded form of the string.
+ #
+ # "hello".format_http
+ # # => "hello"
+ #
+ def format_http(options={})
+ format_bytes(options) { |c| sprintf("%%%x",c) }
end
end