From 8e73afa934fb3743e2a687bc08f535f386ece585 Mon Sep 17 00:00:00 2001 From: Richard Piazza Date: Fri, 17 Apr 2026 09:04:05 -0500 Subject: [PATCH] XML escaping quotes --- Sources/TranslationCatalogIO/Internal/StringsXml.swift | 1 + .../TranslationCatalogTests/ExpressionEncoderTests.swift | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/TranslationCatalogIO/Internal/StringsXml.swift b/Sources/TranslationCatalogIO/Internal/StringsXml.swift index c268eea..211e19f 100644 --- a/Sources/TranslationCatalogIO/Internal/StringsXml.swift +++ b/Sources/TranslationCatalogIO/Internal/StringsXml.swift @@ -39,6 +39,7 @@ struct StringsXml: Codable, DynamicNodeDecoding, DynamicNodeEncoding { ) var string = String(decoding: encoded, as: UTF8.self) string = string.replacingOccurrences(of: "'", with: "\\'") + string = string.replacingOccurrences(of: """, with: "\\\"") string = string.replacingOccurrences(of: " ", with: " ") // Non-Breaking Space return string.data(using: .utf8) ?? encoded } diff --git a/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift b/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift index 2b0a9e2..4d6366d 100644 --- a/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift +++ b/Tests/TranslationCatalogTests/ExpressionEncoderTests.swift @@ -20,7 +20,7 @@ struct ExpressionEncoderTests { Expression( id: UUID(uuidString: "5638B19C-2034-49F2-A163-54CC37269050")!, key: "EXP_02", - value: "Hello %s!", + value: #"Hello "%s"!"#, languageCode: .english ), Expression( @@ -43,7 +43,7 @@ struct ExpressionEncoderTests { Hello World! - Hello %s! + Hello \\\"%s\\\"! Hello %s, welcome to \\'%s\\'! """) @@ -59,7 +59,7 @@ struct ExpressionEncoderTests { let output = String(decoding: data, as: UTF8.self) #expect(output == """ "EXP_01" = "Hello World!"; - "EXP_02" = "Hello %@!"; + "EXP_02" = "Hello \\\"%@\\\"!"; "EXP_03" = "Hello\\U00A0%@, welcome to '%@'!"; """) } @@ -75,7 +75,7 @@ struct ExpressionEncoderTests { #expect(output == """ { "EXP_01" : "Hello World!", - "EXP_02" : "Hello %s!", + "EXP_02" : "Hello \\\"%s\\\"!", "EXP_03" : "Hello %s, welcome to '%s'!" } """)