Class: Firebug::Unserializer

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

Overview

Note:

Hashes will be returned with symbolized keys.

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)


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

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

Instance Attribute Details

#strStringScanner

Returns the current value of str.

Returns:

  • (StringScanner)

    the current value of str



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

def str
  @str
end

Class Method Details

.parse(value) ⇒ Object

Convenience method for unserializing a PHP serialized string.

Parameters:

  • value (String)

Returns:

  • (Object)


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

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

Instance Method Details

#parseObject

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/firebug/unserializer.rb', line 28

def parse # rubocop:disable AbcSize,CyclomaticComplexity
  ch = str.getch
  return if ch.nil?

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