You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/07/13 14:07:44 UTC
[tomcat] branch main updated: Automate handing of POEditor's over zealous escaping
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 45b979bb0f Automate handing of POEditor's over zealous escaping
45b979bb0f is described below
commit 45b979bb0f34bf863b722568ada05bee9b3d7de7
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jul 13 15:07:30 2022 +0100
Automate handing of POEditor's over zealous escaping
---
.../apache/tomcat/buildutil/translate/Import.java | 5 ++++-
.../apache/tomcat/buildutil/translate/Utils.java | 25 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/tomcat/buildutil/translate/Import.java b/java/org/apache/tomcat/buildutil/translate/Import.java
index e1fe9a3ead..d26c45e980 100644
--- a/java/org/apache/tomcat/buildutil/translate/Import.java
+++ b/java/org/apache/tomcat/buildutil/translate/Import.java
@@ -82,7 +82,10 @@ public class Import {
w.write(System.lineSeparator());
}
- w.write(cKey.key + "=" + Utils.formatValueImport(value));
+ value = Utils.formatValueImport(value);
+ value = Utils.fixUnnecessaryEscaping(cKey.key, value);
+
+ w.write(cKey.key + "=" + value);
w.write(System.lineSeparator());
}
if (w != null) {
diff --git a/java/org/apache/tomcat/buildutil/translate/Utils.java b/java/org/apache/tomcat/buildutil/translate/Utils.java
index 4550448ef1..8b12f38d79 100644
--- a/java/org/apache/tomcat/buildutil/translate/Utils.java
+++ b/java/org/apache/tomcat/buildutil/translate/Utils.java
@@ -26,17 +26,28 @@ import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.regex.Pattern;
public class Utils {
private static final Pattern ESCAPE_LEADING_SPACE = Pattern.compile("^(\\s)", Pattern.MULTILINE);
+ private static final Set<String> KEYS_WITH_UNNECESSARY_ESCAPING = new HashSet<>();
+
// Package private so it is visible to tests
static final String PADDING = "POEDITOR_EXPORT_PADDING_DO_NOT_DELETE";
+ static {
+ KEYS_WITH_UNNECESSARY_ESCAPING.add("arrays.malformed.arrays");
+ KEYS_WITH_UNNECESSARY_ESCAPING.add("jsp.error.attribute.deferredmix");
+ KEYS_WITH_UNNECESSARY_ESCAPING.add("jsp.error.el.template.deferred");
+ }
+
+
private Utils() {
// Utility class. Hide default constructor.
}
@@ -86,6 +97,20 @@ public class Utils {
}
+ /*
+ * Values containing "[{n}]" and "'" need to have the "'" escaped as "''".
+ * POEditor attempts to do this automatically but does it for any value
+ * containing "{" or "}" leading to some unnecessary escaping. This method
+ * undoes the unnecessary escaping.
+ */
+ static String fixUnnecessaryEscaping(String key, String value) {
+ if (KEYS_WITH_UNNECESSARY_ESCAPING.contains(key)) {
+ return value.replace("''", "'");
+ }
+ return value;
+ }
+
+
/*
* Common formatting to convert a String for storage as a value in a
* property file.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org