Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message pack improperly serializes maps with numerical indexes #32

Open
joryacooper opened this issue Oct 30, 2018 · 0 comments
Open

Message pack improperly serializes maps with numerical indexes #32

joryacooper opened this issue Oct 30, 2018 · 0 comments

Comments

@joryacooper
Copy link

When emitting a map of data that uses non-sequential numerical indexes, e.g.:

$data = [
    "3" => "foo",
    "7" => "bar"
];
$emitter = new SocketIO\Emitter(); 
$emitter->emit('event', $data);

The data is serialized, emitted, and received as an array, e.g.:

{
    "0": "foo",
    "1": "bar"
}

The only way around this right now is to add a non-numerical key into the map, e.g.:

$data = [
    "3" => "foo",
    "7" => "bar",
    "hack" => true
];
$emitter->emit('event', $data);

The reason this is happening is because in this file (https://github.com/rase-/socket.io-php-emitter/blob/master/src/msgpack_pack.php#L79) starting at line 79, the code is converting the data to an array if all keys in the data are ints, regardless of if the keys are sequential or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant