Skip to content

Commit

Permalink
try escaping double quotes if JSON is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jan 10, 2025
1 parent 47f87d1 commit 6a99ef5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion MyApp.ServiceInterface/AiServerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,16 @@ public static string SanitizeBody(string? body)

if (!string.IsNullOrEmpty(json))
{
var obj = (Dictionary<string,object>)JSON.parse(json);
Dictionary<string, object>? obj = null;
try
{
obj = (Dictionary<string, object>)JSON.parse(json);
}
catch (Exception)
{
json = json.Replace("\"", "\\\"");
obj = (Dictionary<string, object>)JSON.parse(json);
}
var reason = obj.TryGetValue("reason", out var oReason)
? (string)oReason
: null;
Expand Down

0 comments on commit 6a99ef5

Please sign in to comment.