Skip to content

Commit b61a488

Browse files
committed
Short circuit strings in deserialization. Fixes #14
1 parent 4dfc26a commit b61a488

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.7.3:
2+
- Fixed an issue with empty string deserialization, caused by the `EmptyStringToDefault` code in 0.7.2.
3+
14
# 0.7.2:
25
- Added `EmptyStringToDefault` deserialization option, defaults to true.
36
- When true, empty strings will be deserialized into the default value of the target IConvertible.

PhpSerializerNET.Test/TestStrings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ public void SerializeEmptyString() {
3333
PhpSerialization.Serialize("")
3434
);
3535
}
36+
37+
[TestMethod]
38+
public void DeserializeEmptyStringExplicit() {
39+
Assert.AreEqual(
40+
"",
41+
PhpSerialization.Deserialize<string>("s:0:\"\";")
42+
);
43+
}
44+
3645
[TestMethod]
3746
public void SerializeUmlauts() {
3847
Assert.AreEqual(

PhpSerializerNET/PhpDeserializer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ private object DeserializeToken(Type targetType, PhpSerializeToken token) {
132132
case PhpSerializerType.Integer:
133133
case PhpSerializerType.Floating:
134134
case PhpSerializerType.String:
135+
// Short-circuit strings:
136+
if (targetType == typeof(string)) {
137+
return token.Value;
138+
}
139+
135140
if (targetType.IsEnum){
136141
if (token.Type != PhpSerializerType.String){
137142
return ((IConvertible)token.Value).ToType(targetType.GetEnumUnderlyingType(), CultureInfo.InvariantCulture);

0 commit comments

Comments
 (0)