Clean Windows paths before guessing the service name

When encountering windows paths when running in native profile, services
names would not be extracted correctly due to different path separators.
Now they are normalized before being used for service name guessing.

Fixes #531
This commit is contained in:
Stefan Pfeiffer
2016-12-12 17:25:42 +01:00
parent 5eccc4ae45
commit 80bff34cce
2 changed files with 10 additions and 1 deletions

View File

@@ -111,7 +111,7 @@ public class PropertyPathEndpoint
Set<String> services = new LinkedHashSet<>();
if (path != null) {
String stem = StringUtils
.stripFilenameExtension(StringUtils.getFilename(path));
.stripFilenameExtension(StringUtils.getFilename(StringUtils.cleanPath(path)));
// TODO: correlate with service registry
int index = stem.indexOf("-");
while (index >= 0) {

View File

@@ -86,6 +86,15 @@ public class PropertyPathEndpointTests {
.toString());
}
@Test
public void testNotifyOneWithWindowsPath() throws Exception {
assertEquals("[foo]",
this.endpoint
.notifyByPath(new HttpHeaders(), Collections
.<String, Object> singletonMap("path", "C:\\config\\foo.yml"))
.toString());
}
@Test
public void testNotifyOneWithProfile() throws Exception {
assertEquals("[foo:local, foo-local]",