Module: Ronin::Support::Encoding::URI::Form
- Defined in:
- lib/ronin/support/encoding/uri.rb
Overview
Contains methods for encoding/decoding escaping/unescaping URI form data.
Class Method Summary collapse
-
.decode(data) ⇒ String
Alias for Form.unescape.
-
.encode(data, **kwargs) ⇒ String
URI Form encodes every character in the given data.
-
.encode_byte(byte, **kwargs) ⇒ String
URI Form encodes the given byte.
-
.escape(data, **kwargs) ⇒ String
URI Form escapes the String.
-
.escape_byte(byte, **kwargs) ⇒ String
URI Form escapes the given byte.
-
.unescape(data) ⇒ String
URI Form unescapes the String.
Class Method Details
.decode(data) ⇒ String
Alias for unescape.
430 431 432 |
# File 'lib/ronin/support/encoding/uri.rb', line 430 def self.decode(data) unescape(data) end |
.encode(data, **kwargs) ⇒ String
URI Form encodes every character in the given data.
409 410 411 412 413 414 415 416 417 |
# File 'lib/ronin/support/encoding/uri.rb', line 409 def self.encode(data,**kwargs) encoded = String.new data.each_byte do |byte| encoded << encode_byte(byte,**kwargs) end return encoded end |
.encode_byte(byte, **kwargs) ⇒ String
URI Form encodes the given byte.
280 281 282 283 284 |
# File 'lib/ronin/support/encoding/uri.rb', line 280 def self.encode_byte(byte,**kwargs) if byte == 0x20 then '+' else URI.encode_byte(byte,**kwargs) end end |
.escape(data, **kwargs) ⇒ String
URI Form escapes the String.
350 351 352 353 354 355 356 357 358 |
# File 'lib/ronin/support/encoding/uri.rb', line 350 def self.escape(data,**kwargs) escaped = String.new data.each_byte do |byte| escaped << escape_byte(byte,**kwargs) end return escaped end |
.escape_byte(byte, **kwargs) ⇒ String
URI Form escapes the given byte.
315 316 317 318 319 320 321 |
# File 'lib/ronin/support/encoding/uri.rb', line 315 def self.escape_byte(byte,**kwargs) if (byte == 42) || (byte == 45) || (byte == 46) || ((byte >= 48) && (byte <= 57)) || ((byte >= 65) && (byte <= 90)) || (byte == 95) || ((byte >= 97) && (byte <= 122)) byte.chr else encode_byte(byte,**kwargs) end end |
.unescape(data) ⇒ String
URI Form unescapes the String.
375 376 377 378 379 380 381 382 383 |
# File 'lib/ronin/support/encoding/uri.rb', line 375 def self.unescape(data) data.gsub(/(?:\+|%[A-Fa-f0-9]{2})/) do |escaped_char| if escaped_char == '+' ' ' else escaped_char[1..].to_i(16).chr end end end |