Skip to content

Commit 974b129

Browse files
authored
Guard against non-json that looks like json (#1736)
* Guard against non-json that looks like json * Filter out empty spans on client, so server doesn't throw
1 parent be53197 commit 974b129

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

backend/FwLite/LcmCrdt/LcmCrdtDbContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ private class RichStringDbConverter() : ValueConverter<RichString?, string?>(
5656
{
5757
if (maybeJson is null) return null;
5858
if (maybeJson.StartsWith('[') || maybeJson.StartsWith('{'))
59-
return JsonSerializer.Deserialize<RichString?>(maybeJson);
59+
{
60+
try
61+
{
62+
return JsonSerializer.Deserialize<RichString?>(maybeJson);
63+
}
64+
catch { }
65+
}
6066
return new RichString(maybeJson);
6167
}
6268
}

frontend/viewer/src/lib/components/lcm-rich-text-editor/lcm-rich-text-editor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
//todo, eventually we might want to let the user edit span props, not sure if node attributes or marks are the correct way to handle that
8080
//I suspect marks is the right way though.
8181
if (!value) value = {spans: []};
82-
value.spans = newState.doc.children.map((child) => richSpanFromNode(child));
82+
value.spans = newState.doc.children.map((child) => richSpanFromNode(child))
83+
.filter(s => s.text);
8384
dirty = true;
8485
}
8586
editor.updateState(newState);

0 commit comments

Comments
 (0)