Class: Firebug::Unserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/firebug/unserializer.rb

Overview

This class will unserialize a PHP serialized string into a ruby object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Unserializer

Returns a new instance of Unserializer.

Parameters:

  • string (String)


14
15
16
# File 'lib/firebug/unserializer.rb', line 14

def initialize(string)
  self.str = StringIOReader.new(string)
end

Instance Attribute Details

#strStringIOReader

Returns the current value of str.

Returns:



10
11
12
# File 'lib/firebug/unserializer.rb', line 10

def str
  @str
end

Class Method Details

.parse(value) ⇒ Object

Convenience method for unserializing a PHP serialized string.

Parameters:

  • value (String)

Returns:

  • (Object)

See Also:



24
25
26
# File 'lib/firebug/unserializer.rb', line 24

def self.parse(value)
  new(value).parse
end

Instance Method Details

#parseHash, ...

Note:

Hashes will be returned with symbolized keys.

Parse a PHP serialized string into a Ruby object.

Returns:

  • (Hash, Array, String, Integer, Float, nil)

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/firebug/unserializer.rb', line 34

def parse
  ch = str.getc
  return if ch.nil?

  str.getc # : or ;
  case ch
  when 'a'
    parse_enumerable.tap { str.getc }
  when 's'
    parse_string
  when 'i'
    parse_int
  when 'd'
    parse_double
  when 'b'
    parse_bool
  when 'N'
    nil
  else
    raise ParserError, "Unknown token '#{ch}' at position #{str.pos} (#{str.string})"
  end
end