Module: Ethon::Easies::Util

Extended by:
Util
Included in:
Form, Params, Util
Defined in:
lib/ethon/easies/util.rb

Overview

This module contains small helpers.

Instance Method Summary collapse

Instance Method Details

#escape_zero_byte(value) ⇒ String, Object

Escapes zero bytes in strings.

Examples:

Escape zero bytes.

Util.escape_zero_byte("1\0")
#=> "1\\0"

Parameters:

  • value (Object)

    The value to escape.

Returns:

  • (String, Object)

    Escaped String if zero byte found, original object if not.



17
18
19
20
# File 'lib/ethon/easies/util.rb', line 17

def escape_zero_byte(value)
  return value unless value.to_s.include?(0.chr)
  value.to_s.gsub(0.chr, '\\\0')
end