1313import java .io .File ;
1414import java .io .FilenameFilter ;
1515import java .io .IOException ;
16- import java .nio .file .Paths ;
1716import java .util .ArrayList ;
1817import java .util .Arrays ;
1918import java .util .List ;
@@ -62,7 +61,13 @@ protected void addAssetDirectories(Modules modules, String baseDir) {
6261 // classpath needs the trailing / to find child dirs
6362 findResources ("asset module directories" , baseDir , "*" , "*/" ).stream ().forEach (resource -> {
6463 try {
65- File f = new File (resource .getURL ().getFile ());
64+ String resourceFile = resource .getURL ().getFile ();
65+ if (logger .isDebugEnabled ()) {
66+ logger .debug ("Checking resource to see if it's a valid asset directory: " + resourceFile );
67+ }
68+
69+ resourceFile = decodeAssetDirectoryResource (resourceFile );
70+ File f = new File (resourceFile );
6671 String uri = resource .getURI ().toString ();
6772 boolean isRecognized = recognizedPaths .contains (f .getName ());
6873 // when the modules are in a jar inside a war
@@ -81,6 +86,29 @@ protected void addAssetDirectories(Modules modules, String baseDir) {
8186 modules .setAssetDirectories (dirs );
8287 }
8388
89+ /**
90+ * There may be other characters that need decoding, but for now, only %20 is being converted back into a space.
91+ *
92+ * The reason %20 exists is because a Resource that represents a potential asset directory is accessed as a URL in
93+ * order to support jar and war files. Accessing the directory as a URL results in spaces being converted to %20.
94+ * In order to construct a File, these must be converted back into spaces.
95+ *
96+ * It may be that performing a full URL decoding on the resourceFile is the correct solution, just don't have enough
97+ * test cases to know that this is safe for sure.
98+ *
99+ * @param resourceFile
100+ * @return
101+ */
102+ protected String decodeAssetDirectoryResource (String resourceFile ) {
103+ if (resourceFile .contains ("%20" )) {
104+ resourceFile = resourceFile .replaceAll ("%20" , " " );
105+ if (logger .isDebugEnabled ()) {
106+ logger .debug ("Replaced occurrences of %20 with a space in potential asset directory: " + resourceFile );
107+ }
108+ }
109+ return resourceFile ;
110+ }
111+
84112 protected List <String > getRecognizedPaths () {
85113 return Arrays .asList (optionsPath , servicesPath , transformsPath , namespacesPath , schemasPath );
86114 }
0 commit comments