From 155fe96bddc2e76f73acb56b6d545049e921c7b3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 12 Aug 2024 14:59:30 +0800 Subject: [PATCH] Revise quote escaping for translated strings in WebUI qbt only need to escape double quotes for the sake of HTML attributes. As for single quotes it can leave them as-is since WebUI enforce using double quotes for strings. PR #21180. --- src/webui/webapplication.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 6a339d159..d175cb2a5 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -265,9 +265,11 @@ void WebApplication::translateDocument(QString &data) const // it should fallback to `sourceText` QString translation = loadedText.isEmpty() ? sourceText : loadedText; - // Use HTML code for quotes to prevent issues with JS - translation.replace(u'\'', u"'"_s); - translation.replace(u'\"', u"""_s); + // Escape quotes to workaround issues with HTML attributes + // FIXME: this is a dirty workaround to deal with broken translation strings: + // 1. Translation strings is the culprit of the issue, they should be fixed instead + // 2. The escaped quote/string is wrong for JS. JS use backslash to escape the quote: "\"" + translation.replace(u'"', u"""_s); data.replace(i, regexMatch.capturedLength(), translation); i += translation.length(); -- 2.11.4.GIT