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:09:02 UTC

[tomcat] branch 8.5.x 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 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 45390f8a81 Automate handing of POEditor's over zealous escaping
45390f8a81 is described below

commit 45390f8a81f11f48e4ae54a7eba6a5c78b00b8ac
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 1dcdd12375..0c02e69a9a 100644
--- a/java/org/apache/tomcat/buildutil/translate/Import.java
+++ b/java/org/apache/tomcat/buildutil/translate/Import.java
@@ -78,7 +78,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 88d75c669a..63be4e0b44 100644
--- a/java/org/apache/tomcat/buildutil/translate/Utils.java
+++ b/java/org/apache/tomcat/buildutil/translate/Utils.java
@@ -22,16 +22,27 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
 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.
     }
@@ -68,6 +79,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