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 1af1e2bbc4 Better comments and fix broken test.
1af1e2bbc4 is described below
commit 1af1e2bbc4827dc9bf6e205c53ec7258291599ce
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Nov 3 13:26:19 2025 +0000
Better comments and fix broken test.
---
.../apache/tomcat/buildutil/translate/Utils.java | 24 +++++++++++++++++++++-
.../tomcat/buildutil/translate/TestUtils.java | 18 ++++++++++------
2 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/tomcat/buildutil/translate/Utils.java
b/java/org/apache/tomcat/buildutil/translate/Utils.java
index 33af445d34..4851d773f7 100644
--- a/java/org/apache/tomcat/buildutil/translate/Utils.java
+++ b/java/org/apache/tomcat/buildutil/translate/Utils.java
@@ -71,6 +71,14 @@ public class Utils {
}
+ /*
+ * This is the formatting applied when exporting values from Tomcat to POE.
+ *
+ * The values have been read from Tomcat's property files (so the input is
the actual value with none of the
+ * escaping required to represent that value in a property file) and are
being written back out in a single file to
+ * be imported into POEditor. The padding for blank lines needs to be
added followed by the common formatting
+ * required to convert a property value to the representation of that
value in a file.
+ */
static String formatValueExport(String in) {
String result;
@@ -84,6 +92,14 @@ public class Utils {
}
+ /*
+ * This is the formatting applied when importing values to Tomcat from POE.
+ *
+ * The values have been read from POE's property files (so the input is
the actual value with none of the
+ * escaping required to represent that value in a property file) and are
being written back out to individual files
+ * in Tomcat. The padding for blank lines needs to be removed followed by
the common formatting required to convert
+ * a property value to the representation of that value in a file.
+ */
static String formatValueImport(String in) {
String result;
@@ -111,7 +127,13 @@ public class Utils {
/*
- * Common formatting to convert a String for storage as a value in a
property file.
+ * Common formatting to convert a String value for storage as a value in a
property file. Values that contain
+ * line-breaks need the line-break in the value to be replaced with the
correct representation of a line-break in a
+ * property file. Leading space needs to be escaped with a '\' and
horizontal tabs need to be converted to "\t".
+ *
+ * Note that a single '\' needs to be escaped both in a Java string and in
a property file so if a property value
+ * needs to contain a single `\` (e.g. to escape white space at the start
of a line) that will appear as "\\\\" in
+ * the Java code.
*/
static String formatValueCommon(String in) {
String result = in.replace("\n", "\\n\\\n");
diff --git a/test/org/apache/tomcat/buildutil/translate/TestUtils.java
b/test/org/apache/tomcat/buildutil/translate/TestUtils.java
index 85c75bf8a3..d7b4175938 100644
--- a/test/org/apache/tomcat/buildutil/translate/TestUtils.java
+++ b/test/org/apache/tomcat/buildutil/translate/TestUtils.java
@@ -23,30 +23,36 @@ public class TestUtils {
@Test
public void testFormatValue01() {
- // Import from Tomcat
- Assert.assertEquals("\\n\\\n</web-fragment>\\n",
Utils.formatValueImport("\\n\\\n</web-fragment>\\n"));
+ // Import from POE
+ Assert.assertEquals("line1\\n\\\nline2\\n\\\nline3",
Utils.formatValueImport("line1\nline2\nline3"));
}
@Test
public void testFormatValue02() {
- // Import from POEditor
- Assert.assertEquals("\\n\\\n</web-fragment>\\n",
Utils.formatValueImport("\\n</web-fragment>\\n"));
+ // Import from POE
+ Assert.assertEquals("\\n\\\nline2\\n\\\nline3",
Utils.formatValueImport(Utils.PADDING + "\nline2\nline3"));
}
@Test
public void testFormatValue03() {
+ // Import from POE
+ Assert.assertEquals("line1\\n\\\n\\tline2\\n\\\n\\tline3",
Utils.formatValueImport("line1\n\tline2\n\tline3"));
+ }
+
+ @Test
+ public void testFormatValue04() {
// Export from Tomcat
Assert.assertEquals("line1\\n\\\nline2\\n\\\nline3",
Utils.formatValueExport("line1\nline2\nline3"));
}
@Test
- public void testFormatValue04() {
+ public void testFormatValue05() {
// Export from Tomcat
Assert.assertEquals(Utils.PADDING + "\\n\\\nline2\\n\\\nline3",
Utils.formatValueExport("\nline2\nline3"));
}
@Test
- public void testFormatValue05() {
+ public void testFormatValue06() {
// Export from Tomcat
Assert.assertEquals("line1\\n\\\n\\tline2\\n\\\n\\tline3",
Utils.formatValueExport("line1\n\tline2\n\tline3"));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]