Skip to content

Commit 2d70bec

Browse files
committed
Fix #43: Deserialize the key to string properly.
1 parent e9b7e67 commit 2d70bec

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

PhpSerializerNET.Test/Serialize/ObjectSerialization.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public void SerializesToStdClass() {
2323
);
2424
}
2525

26+
[Fact]
27+
public void HandlesIntegerKeys() {
28+
// https://github.com/StringEpsilon/PhpSerializerNET/issues/43
29+
var result = (PhpObjectDictionary)PhpSerialization.Deserialize(
30+
"""O:3:"foo":1:{i:0;s:7:"QG3GHPX";}""",
31+
new() { EnableTypeLookup = false }
32+
);
33+
Assert.Equal("QG3GHPX", result["0"]);
34+
}
35+
2636
[Fact]
2737
public void SerializesToSpecificClass() {
2838
var testObject = new NamedClass() {

PhpSerializerNET/Deserialization/PhpDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private object MakeClass(in PhpToken token) {
297297
var result = new PhpObjectDictionary(token.Length, typeName);
298298
result.SetClassName(typeName);
299299
for (int i = 0; i < token.Length; i++) {
300-
result.TryAdd((string)this.Next(), this.Next());
300+
result.TryAdd((string)this.Next(typeof(string)), this.Next());
301301
}
302302

303303
return result;

0 commit comments

Comments
 (0)