Skip to content

Commit d75028a

Browse files
committed
Do not allow plugins to modify default ASF json serializer settings upon creation
This can only accidentally break things we expect to be operative
1 parent 10a7fe1 commit d75028a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ArchiSteamFarm/Helpers/Json/JsonUtilities.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ private static void ApplyCustomModifiers(JsonTypeInfo jsonTypeInfo) {
116116
}
117117

118118
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
119-
private static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool writeIndented = false) =>
120-
new(JsonSerializerDefaults.Strict) {
119+
private static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool writeIndented = false) {
120+
JsonSerializerOptions result = new(JsonSerializerDefaults.Strict) {
121121
AllowTrailingCommas = true,
122122
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
123123
IndentCharacter = '\t',
@@ -129,6 +129,11 @@ private static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool wri
129129
WriteIndented = writeIndented
130130
};
131131

132+
result.MakeReadOnly();
133+
134+
return result;
135+
}
136+
132137
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2070", Justification = "We don't care about trimmed methods, it's not like we can make it work differently anyway")]
133138
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2075", Justification = "We don't care about trimmed properties, it's not like we can make it work differently anyway")]
134139
private static MethodInfo? GetShouldSerializeMethod([SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")] Type parent, JsonPropertyInfo property) {

0 commit comments

Comments
 (0)