SLING-10043 - Naming OSGi configs with dashes breaks the OSGi installer
rombert: fixed indentation
Closes #6
diff --git a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
index ae0dd75..e4d7b12 100644
--- a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
+++ b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
@@ -121,12 +121,14 @@
//format assumption ::: "factory_pid.factory_pid.pid"
// split pid with lastIndexOf('.') then remove the duplicate factory_pid part from the remaining string using the middle dot split index
final int lastDotIndex = oldId.lastIndexOf('.');
- final String factoryIdString = oldId.substring(0, lastDotIndex + 1); // keep it +1 to have last dot intact
- // so that we always have even dots in
- // the string
- factoryPid = oldId.substring(0, getMiddleDotSplitIndex(factoryIdString));
+ if(lastDotIndex < 0) { //when oldId does not contain any dot
+ factoryPid = oldId;
+ } else {
+ final String factoryIdString = oldId.substring(0, lastDotIndex + 1); // keep it +1 to have last dot intact
+ // so that we always have even dots in the string
+ factoryPid = oldId.substring(0, getMiddleDotSplitIndex(factoryIdString));
+ }
pid = oldId.substring(lastDotIndex+1);
-
}
return new String[] { factoryPid, pid };
diff --git a/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java b/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
index 894a290..204d94e 100644
--- a/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
+++ b/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
@@ -52,6 +52,13 @@
null,
"org.apache.sling.commons.log.LogManager.factory.config.org.apache.sling.commons.log.LogManager.factory.config.3a514ecf-2e1d-4903-bf88-d878360e8ff1",
"org.apache.sling.commons.log.LogManager.factory.config", "3a514ecf-2e1d-4903-bf88-d878360e8ff1");
+
+ // case where alias is null and factoryPid and Pid would be inferred from oldId itself
+ checkFactoryPid(
+ null,
+ "org-test-form-servlet",
+ "org-test-form-servlet", "org-test-form-servlet");
+
}
@Test