Skip to content

Commit

Permalink
Merge pull request wildfly#484 from xstefank/jbeap-13122
Browse files Browse the repository at this point in the history
[JBEAP-13122] Duplicate record is written in property file when group…
  • Loading branch information
jmesnil committed Mar 14, 2018
2 parents ad3bd90 + 8019892 commit f328fac
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class PropertiesFileLoader {
* <ul>
* <li>{@code #username=password}</li>
* <li>{@code username=password}</li>
* <li>{@code #username=group1,group2,...}</li>
* <li>{@code username=group1,group2,...}</li>
* <li>{@code username=} (no group)</li>
* </ul>
*
* The regular expression is used to obtain 2 capturing groups, {@code group(1)} is used to obtain the username,
Expand Down Expand Up @@ -97,7 +100,7 @@ public class PropertiesFileLoader {
*
* Note: Possessive quantifiers are used here as without them invalid test strings become a serious performance burden.
*/
public static final Pattern PROPERTY_PATTERN = Pattern.compile("#?+((?:[,.\\-@/a-zA-Z0-9]++|(?:\\\\[=\\\\])++)++)=(.++)");
public static final Pattern PROPERTY_PATTERN = Pattern.compile("#?+((?:[,.\\-@/a-zA-Z0-9]++|(?:\\\\[=\\\\])++)++)=(.*+)");
public static final String DISABLE_SUFFIX_KEY = "!disable";

private final InjectedValue<PathManager> pathManager = new InjectedValue<PathManager>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

import org.junit.Assert;
Expand Down Expand Up @@ -129,6 +132,40 @@ public void testAdd() throws Exception {
}
}

@Test
public void testDoublePersistWithEmptyValue() throws Exception {
File tmpFile = null;
try {
tmpFile = createTempFile();
writeTestDataToFile(tmpFile);

PropertiesFileLoader loader = new PropertiesFileLoader(tmpFile.getAbsolutePath(), null);
loader.start(null);
Properties props = loader.getProperties();
props.put("EMPTY", "");
loader.persistProperties();

props = loader.getProperties();
props.put("NEW", "VALUE");
loader.persistProperties();
loader.stop(null);

//verify all properties are present
PropertiesFileLoader loader2 = new PropertiesFileLoader(tmpFile.getAbsolutePath(), null);
loader2.start(null);
Properties props2 = loader2.getProperties();
verifyProperties(props2, props2.size()-2, "NEW", "VALUE");
loader2.stop(null);

//verify that key is present only once
Assert.assertEquals(properties.length + 2,
Files.lines(Paths.get(tmpFile.getAbsolutePath()), Charset.defaultCharset()).count());

} finally {
cleanupTempFile(tmpFile);
}
}

@Test
public void testRemove() throws Exception {
File tmpFile = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void testEntry(final String entry, final boolean isValid, final String u
@Test
public void testAllEntries() {
String[] usernameParts = new String[] { "abc", "DEF", "\\\\", ",", "\\=", "@", "-", "012", ".", "/" };
String[] passwordParts = new String[] { "ghi", "JKL", "\\\\", "\\=", "345" };
String[] passwordParts = new String[] { "", ",", "ghi", "JKL", "\\\\", "\\=", "345" };

for (int usernameStart = 0; usernameStart < usernameParts.length; usernameStart++) {
for (int usernameMid = 0; usernameMid < usernameParts.length; usernameMid++) {
Expand Down

0 comments on commit f328fac

Please sign in to comment.