From 1c8ab19f83724926bb6aa48a4e9c262502291503 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Sat, 4 Dec 2021 19:01:12 +0100 Subject: [PATCH] [fix] gettext: don't replace backslash characters (#8511) Everything in string.gsub() is replaced, not only the matching group. By using two groups, we can correctly return the full matched string when none of the special conditions apply. Fixes . --- frontend/gettext.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/gettext.lua b/frontend/gettext.lua index ce76c75d4..3f848b72b 100644 --- a/frontend/gettext.lua +++ b/frontend/gettext.lua @@ -61,7 +61,7 @@ function GetText_mt.__call(gettext, msgid) return gettext.translation[msgid] or gettext.wrapUntranslated(msgid) end -local function c_escape(what) +local function c_escape(what_full, what) if what == "\n" then return "" elseif what == "a" then return "\a" elseif what == "b" then return "\b" @@ -72,7 +72,7 @@ local function c_escape(what) elseif what == "v" then return "\v" elseif what == "0" then return "\0" -- shouldn't happen, though else - return what + return what_full end end @@ -138,7 +138,7 @@ end local function addTranslation(msgctxt, msgid, msgstr, n) -- translated string - local unescaped_string = string.gsub(msgstr, "\\(.)", c_escape) + local unescaped_string = string.gsub(msgstr, "(\\(.))", c_escape) if msgctxt and msgctxt ~= "" then if not GetText.context[msgctxt] then GetText.context[msgctxt] = {}