diff --git a/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs b/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs index bb5eaf6..154fef1 100644 --- a/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs +++ b/src/Helldivers-2-SourceGen/Parsers/PlanetRegionsParser.cs @@ -19,10 +19,11 @@ protected override (string Type, string Source) Parse(string json) var index = property.Name; var name = property.Value.GetProperty("name").GetString(); string? description = property.Value.GetProperty("description").GetString(); + if (string.IsNullOrWhiteSpace(description)) description = "null"; else - description = $@"""{description}"""; + description = $"\"{EscapeSpecialChars(description)}\""; builder.AppendLine($@"{'\t'}{'\t'}{{ {index}, (""{name}"", {description}) }},"); } @@ -30,4 +31,15 @@ protected override (string Type, string Source) Parse(string json) builder.Append("\t}"); return ("IReadOnlyDictionary", builder.ToString()); } + + static string EscapeSpecialChars(string value) + { + return value + .Replace("\\", "\\\\") + .Replace("\"", "\\\"") + .Replace("\r", "\\r") + .Replace("\n", "\\n") + .Replace("\t", "\\t"); + } + }