Marcin Ziąbek 1 год назад
Родитель
Сommit
1ea86bcd96

+ 1 - 5
Source/QuestPDF/Fluent/DocumentOperation.cs

@@ -318,11 +318,7 @@ public class DocumentOperation
     /// </param>
     public DocumentOperation ExtendMetadata(string metadata)
     {
-        Configuration.ExtendMetadata = metadata
-            .Replace("\"", "\\\"")
-            .Replace("\n", "\\n")
-            .Replace("\r", "");
-        
+        Configuration.ExtendMetadata = metadata;
         return this;
     }
     

+ 39 - 2
Source/QuestPDF/Qpdf/SimpleJsonSerializer.cs

@@ -51,8 +51,8 @@ class SimpleJsonSerializer
         if (value == null) 
             return "null";
         
-        if (value is string) 
-            return $"\"{value}\"";
+        if (value is string text) 
+            return $"\"{EscapeStringForJson(text)}\"";
         
         if (value is bool)
             return value.ToString().ToLower();
@@ -78,4 +78,41 @@ class SimpleJsonSerializer
         
         return value.ToString();
     }
+
+    private static string EscapeStringForJson(string input)
+    {
+        if (string.IsNullOrEmpty(input))
+            return input;
+
+        var builder = new StringBuilder(input.Length);
+
+        foreach (char c in input)
+        {
+            if (c == '\\')
+                builder.Append("\\\\");
+            
+            else if (c == '"')
+                builder.Append("\\\"");
+            
+            else if (c == '\b')
+                builder.Append("\\b");
+            
+            else if (c == '\f')
+                builder.Append("\\f");
+            
+            else if (c == '\n')
+                builder.Append("\\n");
+            
+            else if (c == '\r')
+                builder.Append("\\r");
+            
+            else if (c == '\t')
+                builder.Append("\\t");
+            
+            else
+                builder.Append(c);
+        }
+
+        return builder.ToString();
+    }
 }

+ 1 - 1
Source/QuestPDF/QuestPDF.csproj

@@ -3,7 +3,7 @@
         <Authors>MarcinZiabek</Authors>
         <Company>CodeFlint</Company>
         <PackageId>QuestPDF</PackageId>
-        <Version>2024.12.0-rc2</Version>
+        <Version>2024.12.0-rc3</Version>
         <PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API. Easily generate PDF reports, invoices, exports, etc.</PackageDescription>
         <PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/Resources/ReleaseNotes.txt"))</PackageReleaseNotes>
         <LangVersion>12</LangVersion>

+ 4 - 0
Source/QuestPDF/Resources/ReleaseNotes.txt

@@ -19,3 +19,7 @@ Version 2024.12.0-rc1
 
 Version 2024.12.0-rc2
 - Fixed: The text underline decoration was not rendering correctly.
+
+
+Version 2024.12.0-rc3
+- Fixed: When executing document operation on Windows, escaping file paths does not work as expected.