Commit 6ec0b4ca authored by Andy Wilkinson's avatar Andy Wilkinson

Only consider letters when checking if a name is upper-case

Previously, for a string to be considered upper-case,
EmbeddedServerPortFileWriter required every character in the
string to be upper-case. This meant that strings containing numbers were
considered lower-case even if every letter in the string was upper-case.
OS X’s case-preserving, case-insensitive file system masked this problem
as the tests were still able to find the created file, even though the
case of its name was not as expected.

This commit updates EmbeddedServerPortFileWriter to only require
characters that are letters (as defined by Character.isLetter()) to be
upper-case. It also updates the tests to verify that the case of the
created file’s name is correct in such a way that it will fail, even
on OS X, when it is not.

Fixes gh-1676
parent 8ffe7ec4
...@@ -35,6 +35,8 @@ import org.springframework.util.StringUtils; ...@@ -35,6 +35,8 @@ import org.springframework.util.StringUtils;
* *
* @author David Liu * @author David Liu
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson
*
* @since 1.2.0 * @since 1.2.0
*/ */
public class EmbeddedServerPortFileWriter implements public class EmbeddedServerPortFileWriter implements
...@@ -122,7 +124,8 @@ public class EmbeddedServerPortFileWriter implements ...@@ -122,7 +124,8 @@ public class EmbeddedServerPortFileWriter implements
private boolean isUpperCase(String name) { private boolean isUpperCase(String name) {
for (int i = 0; i < name.length(); i++) { for (int i = 0; i < name.length(); i++) {
if (!Character.isUpperCase(name.charAt(i))) { if (Character.isLetter(name.charAt(i))
&& !Character.isUpperCase(name.charAt(i))) {
return false; return false;
} }
} }
......
...@@ -18,6 +18,8 @@ package org.springframework.boot.actuate.system; ...@@ -18,6 +18,8 @@ package org.springframework.boot.actuate.system;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
...@@ -31,6 +33,7 @@ import org.springframework.util.FileCopyUtils; ...@@ -31,6 +33,7 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -40,6 +43,7 @@ import static org.mockito.Mockito.mock; ...@@ -40,6 +43,7 @@ import static org.mockito.Mockito.mock;
* *
* @author David Liu * @author David Liu
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson
*/ */
public class EmbeddedServerPortFileWriterTests { public class EmbeddedServerPortFileWriterTests {
...@@ -84,6 +88,7 @@ public class EmbeddedServerPortFileWriterTests { ...@@ -84,6 +88,7 @@ public class EmbeddedServerPortFileWriterTests {
+ StringUtils.getFilenameExtension(file.getName()); + StringUtils.getFilenameExtension(file.getName());
assertThat(FileCopyUtils.copyToString(new FileReader(new File(file assertThat(FileCopyUtils.copyToString(new FileReader(new File(file
.getParentFile(), managementFile))), equalTo("9090")); .getParentFile(), managementFile))), equalTo("9090"));
assertThat(collectFileNames(file.getParentFile()), hasItem(managementFile));
} }
@Test @Test
...@@ -99,7 +104,7 @@ public class EmbeddedServerPortFileWriterTests { ...@@ -99,7 +104,7 @@ public class EmbeddedServerPortFileWriterTests {
+ StringUtils.getFilenameExtension(file.getName()); + StringUtils.getFilenameExtension(file.getName());
assertThat(FileCopyUtils.copyToString(new FileReader(new File(file assertThat(FileCopyUtils.copyToString(new FileReader(new File(file
.getParentFile(), managementFile))), equalTo("9090")); .getParentFile(), managementFile))), equalTo("9090"));
assertThat(collectFileNames(file.getParentFile()), hasItem(managementFile));
} }
private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) { private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) {
...@@ -112,4 +117,14 @@ public class EmbeddedServerPortFileWriterTests { ...@@ -112,4 +117,14 @@ public class EmbeddedServerPortFileWriterTests {
return event; return event;
} }
private Set<String> collectFileNames(File directory) {
Set<String> names = new HashSet<String>();
if (directory.isDirectory()) {
for (File file : directory.listFiles()) {
names.add(file.getName());
}
}
return names;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment