Module: Arachni::UI::Web::Utilities
- Included in:
- AddonManager, InstanceManager, Scheduler, Server
- Defined in:
- lib/arachni/ui/web/utilities.rb
Overview
General utility methods.
Instance Method Summary collapse
-
#escape(str) ⇒ String
Escapes HTML chars.
-
#escape_hash(hash) ⇒ Hash
Recursively escapes all HTML characters.
-
#parse_datetime(datetime) ⇒ Time
Parses datetime strings such as 07/23/2011 15:34 into Time objects.
-
#remove_proto(url) ⇒ String
Removes the protocol from URL string.
-
#unescape(str) ⇒ String
Unescapes HTML chars.
-
#unescape_hash(hash) ⇒ Hash
Recursively unescapes all HTML characters.
Instance Method Details
#escape(str) ⇒ String
Escapes HTML chars.
40 41 42 |
# File 'lib/arachni/ui/web/utilities.rb', line 40 def escape( str ) CGI.escapeHTML( str || '' ) end |
#escape_hash(hash) ⇒ Hash
Recursively escapes all HTML characters.
64 65 66 67 68 69 70 71 72 |
# File 'lib/arachni/ui/web/utilities.rb', line 64 def escape_hash( hash ) hash.each_pair { |k, v| hash[k] = escape( hash[k] ) if hash[k].is_a?( String ) hash[k] = escape_hash( v ) if v.is_a? Hash } return hash end |
#parse_datetime(datetime) ⇒ Time
Parses datetime strings such as 07/23/2011 15:34 into Time objects.
98 99 100 101 102 103 104 105 |
# File 'lib/arachni/ui/web/utilities.rb', line 98 def parse_datetime( datetime ) date, time = datetime.split( ' ' ) month, day, year = date.split( '/' ) hour, minute = time.split( ':' ) Time.new( year, month, day, hour, minute ) end |
#remove_proto(url) ⇒ String
Removes the protocol from URL string.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/arachni/ui/web/utilities.rb', line 114 def remove_proto( url ) url #begin # url = URI.parse( url ) # scheme = url.scheme + '://' # escape( url.to_s.gsub( scheme, '' ) ) #rescue # return url #end end |
#unescape(str) ⇒ String
Unescapes HTML chars.
53 54 55 |
# File 'lib/arachni/ui/web/utilities.rb', line 53 def unescape( str ) CGI.unescapeHTML( str || '' ) end |
#unescape_hash(hash) ⇒ Hash
Recursively unescapes all HTML characters.
81 82 83 84 85 86 87 88 89 |
# File 'lib/arachni/ui/web/utilities.rb', line 81 def unescape_hash( hash ) hash.each_pair { |k, v| hash[k] = unescape( hash[k] ) if hash[k].is_a?( String ) hash[k] = unescape_hash( v ) if v.is_a? Hash } return hash end |