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.
This commit is contained in:
Chocobo1 2024-08-12 14:59:30 +08:00 committed by GitHub
parent 9a8572bd21
commit 155fe96bdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();