Skip to content

Commit 6303413

Browse files
committed
Account for closing bracket in validateformat correctly.
Fixes #11
1 parent 53a381a commit 6303413

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

PhpSerializerNET.Test/DeserializeObjects.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public void DeserializeObjectWithExcessKeys() {
6161
);
6262
Assert.IsNotNull(deserializedObject);
6363
}
64+
[TestMethod]
65+
66+
public void Test_Issue11() {
67+
var deserializedObject = PhpSerialization.Deserialize(
68+
"a:1:{i:0;a:7:{s:1:\"A\";N;s:1:\"B\";N;s:1:\"C\";s:1:\"C\";s:5:\"odSdr\";i:1;s:1:\"D\";d:1;s:1:\"E\";N;s:1:\"F\";a:3:{s:1:\"X\";i:8;s:1:\"Y\";N;s:1:\"Z\";N;}}}",
69+
);
70+
Assert.IsNotNull(deserializedObject);
71+
}
6472

6573
[TestMethod]
6674
public void ThrowsOnExcessKeys() {

PhpSerializerNET.Test/TestDeserializeErrors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void DeserializeMalformedString() {
5454
Assert.AreEqual("Malformed string at position 0", ex.Message);
5555

5656
ex = Assert.ThrowsException<DeserializationException>(() => PhpSerialization.Deserialize("s:30:\"\";"));
57-
Assert.AreEqual("Illegal length of 30. The string at position 0 pointed to out of bounds index 36.", ex.Message);
57+
Assert.AreEqual("Illegal length of 30. The string at position 0 points to out of bounds index 36.", ex.Message);
5858

5959
ex = Assert.ThrowsException<DeserializationException>(() => PhpSerialization.Deserialize("s:1:\"\";"));
6060
Assert.AreEqual("String at position 0 has an incorrect length of 1: Expected double quote at position 6, found ';' instead.", ex.Message);

PhpSerializerNET/PhpTokenizer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal bool ValidateFormat(ref int position, bool inArray = false) {
7676
}
7777
position += match.Length;
7878
ValidateFormat(ref position, true);
79-
79+
position++; // Account for the closing bracket.
8080
break;
8181
}
8282
case 'O': {
@@ -86,6 +86,7 @@ internal bool ValidateFormat(ref int position, bool inArray = false) {
8686
}
8787
position += match.Length;
8888
ValidateFormat(ref position, true);
89+
position++; // Account for the closing bracket.
8990

9091
break;
9192
}

docs/Deserializing.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var foo = PhpSerialization.Deserialize(
7979
// Whether or not properties are matched case sensitive.
8080
public bool CaseSensitiveProperties = true,
8181

82-
// If true, keys present in the array but not on the target class will be ignored.
82+
// If true, keys present in the array / object but not on the target class or struct will be ignored.
8383
// Otherwise an exception will be thrown.
8484
public bool AllowExcessKeys = false,
8585

@@ -95,4 +95,5 @@ var foo = PhpSerialization.Deserialize(
9595

9696
# Deserializing php objects
9797

98-
TODO.
98+
TODO.
99+

0 commit comments

Comments
 (0)