Permalink
Browse files

Fixing an error in CommandResult that was causing exceptions when pro…

…cessing save command results
  • Loading branch information...
1 parent 20433ac commit a167bb8af28b0ee8065633ab002d355a059c51c5 @arobson arobson committed Jun 17, 2010
Showing with 17 additions and 8 deletions.
  1. +17 −8 src/Relax/Impl/Commands/CommandResult.cs
View
25 src/Relax/Impl/Commands/CommandResult.cs
@@ -1,5 +1,7 @@
using System;
+using System.IO;
using System.Linq;
+using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Symbiote.Core.Extensions;
@@ -38,18 +40,25 @@ public virtual string FilterOutDesignDocuments(string json)
{
if(json == null)
{
- return "";
+ return "";
}
try
{
- var jsonDoc = JObject.Parse(json);
- if(jsonDoc["rows"] != null)
- jsonDoc["rows"]
- .Children()
- .Where(x => x["doc"]["_id"].ToString().StartsWith(@"""_design"))
- .ForEach(x => x.Remove());
- return jsonDoc.ToString();
+ var jToken = JToken.ReadFrom(new JsonTextReader(new StringReader(json)));
+ if (jToken.Type == JTokenType.Array)
+ {
+ return json;
+ }
+ else
+ {
+ if(jToken["rows"] != null)
+ jToken["rows"]
+ .Children()
+ .Where(x => x["doc"]["_id"].ToString().StartsWith(@"""_design"))
+ .ForEach(x => x.Remove());
+ return jToken.ToString();
+ }
}
catch (Exception e)
{

0 comments on commit a167bb8

Please sign in to comment.