summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThakee Nathees <thakeenathees@gmail.com>2020-03-20 08:47:43 +0100
committerRémi Verschelde <rverschelde@gmail.com>2020-03-20 08:48:11 +0100
commit8c3ad2af93a119f45e0bc786ae1dfa04e116d60f (patch)
treec85674bec84b0d1a51afb3c70d3d1e91c9c9b0bb
parent4857648a16585bbd0fb2fbc33d3d0f768b8223b5 (diff)
i18n: Fix parsing of multiple escapes before quotes
See https://github.com/godotengine/godot/pull/37114#issuecomment-601463765
-rw-r--r--core/io/translation_loader_po.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index f1d3f19b58..5da236d029 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -118,17 +118,26 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, RES(), f->get_path() + ":" + itos(line) + " Invalid line '" + l + "' while parsing: ");
l = l.substr(1, l.length());
- //find final quote
+ // Find final quote, ignoring escaped ones (\").
+ // The escape_next logic is necessary to properly parse things like \\"
+ // where the blackslash is the one being escaped, not the quote.
int end_pos = -1;
+ bool escape_next = false;
for (int i = 0; i < l.length(); i++) {
+ if (l[i] == '\\' && !escape_next) {
+ escape_next = true;
+ continue;
+ }
- if (l[i] == '"' && (i == 0 || l[i - 1] != '\\')) {
+ if (l[i] == '"' && !escape_next) {
end_pos = i;
break;
}
+
+ escape_next = false;
}
- ERR_FAIL_COND_V_MSG(end_pos == -1, RES(), f->get_path() + ":" + itos(line) + " Expected '\"' at end of message while parsing file: ");
+ ERR_FAIL_COND_V_MSG(end_pos == -1, RES(), f->get_path() + ":" + itos(line) + ": Expected '\"' at end of message while parsing file.");
l = l.substr(0, end_pos);
l = l.c_unescape();