Per Eric’s suggestion I adjusted the Quotable String Util
This requires the output of the register namespace to contain double-quotes when it has special characters
diff --git a/src/main/java/org/apache/sling/repoinit/parser/impl/QuotableStringUtil.java b/src/main/java/org/apache/sling/repoinit/parser/impl/QuotableStringUtil.java
index 1c0d327..cf27c2b 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/impl/QuotableStringUtil.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/impl/QuotableStringUtil.java
@@ -24,8 +24,7 @@
public class QuotableStringUtil {
- private static final Pattern REQUIRES_QUOTES = Pattern.compile("[\\s|\\\\]");
-
+ private static final Pattern REQUIRES_NO_QUOTES = Pattern.compile("[a-zA-Z0-9-_\\./:*@]+");
private QuotableStringUtil() {
// hidden
}
@@ -39,8 +38,8 @@
*/
@NotNull
public static final String forRepoInitString(@NotNull String string) {
- return REQUIRES_QUOTES.matcher(string).find() ? "\"" + string + "\""
- : string;
+ return REQUIRES_NO_QUOTES.matcher(string).matches() ? string :
+ "\"" + string + "\"";
}
/**
diff --git a/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java b/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java
index 9e6d3e0..2374455 100644
--- a/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java
+++ b/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java
@@ -28,7 +28,7 @@
public RegisterNamespace(String prefix, String uri) {
this.prefix = prefix;
- this.uri = uri;
+ this.uri = cleanupQuotedString(uri);
}
@Override
@@ -46,8 +46,9 @@
@NotNull
@Override
- public String asRepoInitString() {
- return String.format("register namespace ( %s ) %s%n", prefix, uri);
+ public String asRepoInitString()
+ {
+ return String.format("register namespace ( %s ) %s%n", prefix, QuotableStringUtil.forRepoInitString(uri));
}
@Override
diff --git a/src/test/resources/testcases/test-40-output.txt b/src/test/resources/testcases/test-40-output.txt
index bb28ce4..010275f 100644
--- a/src/test/resources/testcases/test-40-output.txt
+++ b/src/test/resources/testcases/test-40-output.txt
@@ -1,3 +1,3 @@
RegisterNamespace (foo) uri:some-uri/V/1.0
RegisterNamespace (prefix_with-other.things) andSimpleURI
-RegisterNamespace (foo2) uri:some-uri/V/1.1/test#
\ No newline at end of file
+RegisterNamespace (foo2) "uri:some-uri/V/1.1/test#"
\ No newline at end of file