Method: Ronin::Support::Encoding::HTML.encode

Defined in:
lib/ronin/support/encoding/html.rb

.encode(data, **kwargs) ⇒ String

Encodes each character in the given data as an HTML character.

Examples:

Encoding::HTML.encode("abc")
# => "abc"

Zero-padding:

Encoding::HTML.encode("abc", zero_pad: true)
# => "abc"

Hexadecimal encoded characters:

Encoding::HTML.encode("abc", format: :hex)
# => "abc"

Uppercase hexadecimal encoded characters:

Encoding::HTML.encode("abc\xff", format: :hex, case: :upper)
# => "abcÿ"

Parameters:

  • data (String)

    The data to HTML encode.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Options Hash (**kwargs):

  • :format (:decimal, :hex) — default: :decimal

    The numeric format for the escaped characters.

  • :zero_pad (Boolean)

    Controls whether the escaped characters will be left-padded with up to seven 0 characters.

  • :case (:lower, :upper, nil)

    Controls whether to output lowercase or uppercase XML special characters. Defaults to lowercase hexadecimal.

Returns:

  • (String)

    The HTML encoded String.

Raises:

  • (ArgumentError)

    The format: or case: keyword argument is invalid.

Since:

  • 1.0.0



169
170
171
# File 'lib/ronin/support/encoding/html.rb', line 169

def self.encode(data,**kwargs)
  XML.encode(data,**kwargs)
end