Skip to content

session key surrounded by spaces #22

@noraj

Description

@noraj

I have a PHP sessions files generated by PHP where the 2 first keys are surrounded by spaces (I really don't know why), which makes the parser crashes.

-session_id|i:42;user_data|a:1:{s:3:"uid";i:666;}blabla_key|N;is_foo|b:0
+ session_id |i:42; user_data |a:1:{s:3:"uid";i:666;}blabla_key|N;is_foo|b:0
/home/noraj/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/bundler/gems/php-serialize-68c0b6f9a20c/lib/php_serialize.rb:270:in 'PHP.do_unserialize': Unable to unserialize type ' ' (TypeError)

                                raise TypeError, "Unable to unserialize type '#{type}'"
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /home/noraj/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/bundler/gems/php-serialize-68c0b6f9a20c/lib/php_serialize.rb:174:in 'PHP.unserialize'
        from formatter_jqr_php-serialize.rb:16:in '<main>'

It's due to the regexp here not taking spaces into accounts

while string.string[string.pos, 32] =~ /^(\w+)\|/ # session_name|serialized_data

As a quick fix I modified the regexp to take into account when the key is surrounded by spaces.

- while string.string[string.pos, 32] =~ /^(\w+)\|/ # session_name|serialized_data
+ while string.string[string.pos, 32] =~ /^\s*(\w+)\s*\|/ # session_name|serialized_data

I don't know if it is the best solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions