[ https://issues.apache.org/jira/browse/MSHARED-1453?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17901429#comment-17901429 ]
ASF GitHub Bot commented on MSHARED-1453: ----------------------------------------- gnodet commented on code in PR #77: URL: https://github.com/apache/maven-archiver/pull/77#discussion_r1860344521 ########## src/test/java/org/apache/maven/shared/archiver/PomPropertiesUtilTest.java: ########## @@ -81,4 +82,36 @@ void testUnicodeEscape() throws IOException { assertEquals("version=2.1.5", contents.get(2)); assertEquals(3, contents.size()); } + + @Test + void testWhitespaceEscape() throws IOException { + Path pomPropertiesFile = tempDirectory.resolve("bar.properties"); + Path customPomPropertiesFile = tempDirectory.resolve("custom.properties"); + try (Writer out = Files.newBufferedWriter(customPomPropertiesFile, StandardCharsets.ISO_8859_1)) { + out.write("a\\u0020key\\u0020with\\u0009whitespace=value\\u0020with\\u0009whitespace\n"); + } + + util.createPomProperties( + (Session) null, + "org.foo", + "こんにちは", + "2.1.5", + new JarArchiver(), + customPomPropertiesFile, + pomPropertiesFile, + true); + assertThat(pomPropertiesFile).exists(); + + Properties actual = new Properties(); + actual.load(Files.newInputStream(pomPropertiesFile)); + assertEquals("value with\twhitespace", actual.getProperty("a key with\twhitespace")); + + // Now read the file directly to check for alphabetical order and encoding + List<String> contents = Files.readAllLines(pomPropertiesFile, StandardCharsets.ISO_8859_1); + assertEquals(4, contents.size()); + assertEquals("a\\ key\\ with\\\twhitespace=value\\ with\\\twhitespace", contents.get(0)); Review Comment: the test is wrong afaik. The mechanism is different for keys and values > Then every entry in this Properties table is written out, one per line. For each entry the key string is written, then an ASCII =, then the associated element string. For the key, all space characters are written with a preceding \ character. For the element, leading space characters, but not embedded or trailing space characters, are written with a preceding \ character. The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded. > Canonicalize properties files for reproducible builds > ----------------------------------------------------- > > Key: MSHARED-1453 > URL: https://issues.apache.org/jira/browse/MSHARED-1453 > Project: Maven Shared Components > Issue Type: Bug > Components: maven-archiver > Reporter: Elliotte Rusty Harold > Assignee: Elliotte Rusty Harold > Priority: Minor > > See discussion on https://github.com/apache/maven-archiver/pull/77/files > Briefly, properties files have non-unique representations and there's no > guarantee two JDKs from different companies and Java versions produce the > same byte-per-byte serialization. Our current code accounts for property > order and comments, but not variations in escaping (hex vs. UTF-8), separator > characters, and insignificant whitespace. -- This message was sent by Atlassian Jira (v8.20.10#820010)