Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/MongoDB.Bson/IO/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,12 @@ protected override void Dispose(bool disposing)
// private methods
private string EscapedString(string value)
{
if (value.All(c => !NeedsEscaping(c)))
if (!NeedsEscaping(value))
{
return value;
}

var sb = new StringBuilder(value.Length);
var sb = new StringBuilder(value.Length * 2);

foreach (char c in value)
{
Expand Down Expand Up @@ -935,6 +935,19 @@ private string GuidToString(BsonBinarySubType subType, byte[] bytes, GuidReprese
}
}

private static bool NeedsEscaping(string text)
{
foreach (var letter in text)
{
if (NeedsEscaping(letter))
{
return true;
}
}

return false;
}

private static bool NeedsEscaping(char c)
{
switch (c)
Expand Down