Skip to content

Commit

Permalink
Fixed CSHARP-147. It was not reading the closing "}" of the extended …
Browse files Browse the repository at this point in the history
…JSON representation for binary data.
  • Loading branch information
rstam committed Jan 14, 2011
1 parent f60f354 commit d56552b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions Bson/IO/JsonReader.cs
Expand Up @@ -509,6 +509,7 @@ JsonToken token
var message = string.Format("JSON reader expected a string but found: '{0}'", subTypeToken.Lexeme);
throw new FileFormatException(message);
}
VerifyToken("}");
var subType = (BsonBinarySubType) Convert.ToInt32(subTypeToken.Lexeme, 16);
currentValue = new BsonBinaryData(bytes, subType);
return BsonType.Binary;
Expand Down
1 change: 1 addition & 0 deletions BsonUnitTests/BsonUnitTests.csproj
Expand Up @@ -109,6 +109,7 @@
<Compile Include="Jira\CSharp122Tests.cs" />
<Compile Include="Jira\CSharp133Tests.cs" />
<Compile Include="Jira\CSharp146Tests.cs" />
<Compile Include="Jira\CSharp147Tests.cs" />
<Compile Include="Jira\CSharp70Tests.cs" />
<Compile Include="Jira\CSharp71Tests.cs" />
<Compile Include="Jira\CSharp74Tests.cs" />
Expand Down
50 changes: 50 additions & 0 deletions BsonUnitTests/Jira/CSharp147Tests.cs
@@ -0,0 +1,50 @@
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using NUnit.Framework;

using MongoDB.Bson;
using MongoDB.Bson.DefaultSerializer;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;

namespace MongoDB.BsonUnitTests.Jira.CSharp147 {
[TestFixture]
public class CSharp146Tests {
public class Parent {
public Child Child { get; set; }
}

public class Child {
public Guid Id { get; set; }
public int A { get; set; }
}

[Test]
public void Test() {
var p = new Parent { Child = new Child() };
p.Child.A = 1;
var json = p.ToJson();
BsonSerializer.Deserialize<Parent>(json); // throws Unexpected element exception
}
}
}

0 comments on commit d56552b

Please sign in to comment.