From 78637dc14f51712e7cc81be275e98a6a325b0ae3 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 06:44:58 +0000 Subject: [PATCH] fix(i18n): escape quoted strings Co-Authored-By: Virgil --- grammar.go | 3 ++- grammar_test.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/grammar.go b/grammar.go index fe85c22..15ae392 100644 --- a/grammar.go +++ b/grammar.go @@ -2,6 +2,7 @@ package i18n import ( "maps" + "strconv" "strings" "text/template" "unicode" @@ -742,7 +743,7 @@ func renderWordOrTitle(lang, word string) string { // Quote wraps a string in double quotes. func Quote(s string) string { - return `"` + s + `"` + return strconv.Quote(s) } // ArticlePhrase prefixes a noun phrase with the correct article. diff --git a/grammar_test.go b/grammar_test.go index 99e9a3e..1d995f6 100644 --- a/grammar_test.go +++ b/grammar_test.go @@ -511,6 +511,9 @@ func TestQuote(t *testing.T) { if got := Quote("hello"); got != `"hello"` { t.Errorf("Quote(%q) = %q, want %q", "hello", got, `"hello"`) } + if got := Quote(`a "quoted" path\name`); got != `"a \"quoted\" path\\name"` { + t.Errorf("Quote(%q) = %q, want %q", `a "quoted" path\name`, got, `"a \"quoted\" path\\name"`) + } } func TestCaseHelpers(t *testing.T) { -- 2.45.3