File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
main/java/com/github/mustachejava/resolver
test/java/com/github/mustachejava/resolver Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 6
6
import java .io .InputStream ;
7
7
import java .io .InputStreamReader ;
8
8
import java .io .Reader ;
9
+ import java .net .URI ;
9
10
import java .nio .charset .StandardCharsets ;
10
11
11
12
/**
@@ -33,11 +34,12 @@ public Reader getReader(String resourceName) {
33
34
ClassLoader ccl = Thread .currentThread ().getContextClassLoader ();
34
35
35
36
String fullResourceName = concatResourceRootAndResourceName (resourceName );
37
+ String normalizeResourceName = URI .create (fullResourceName ).normalize ().getPath ();
36
38
37
- InputStream is = ccl .getResourceAsStream (fullResourceName );
39
+ InputStream is = ccl .getResourceAsStream (normalizeResourceName );
38
40
if (is == null ) {
39
41
ClassLoader classLoader = ClasspathResolver .class .getClassLoader ();
40
- is = classLoader .getResourceAsStream (fullResourceName );
42
+ is = classLoader .getResourceAsStream (normalizeResourceName );
41
43
}
42
44
43
45
if (is != null ) {
Original file line number Diff line number Diff line change @@ -65,4 +65,17 @@ public void getReaderNullRootAndNullResourceThrowsNullPointer() throws Exception
65
65
underTest .getReader (null );
66
66
}
67
67
68
+ @ Test
69
+ public void getReaderWithRootAndResourceHasDoubleDotRelativePath () throws Exception {
70
+ ClasspathResolver underTest = new ClasspathResolver ("templates" );
71
+ Reader reader = underTest .getReader ("absolute/../absolute_partials_template.html" );
72
+ assertThat (reader , is (notNullValue ()));
73
+ }
74
+
75
+ @ Test
76
+ public void getReaderWithRootAndResourceHasDotRelativePath () throws Exception {
77
+ ClasspathResolver underTest = new ClasspathResolver ("templates" );
78
+ Reader reader = underTest .getReader ("absolute/./nested_partials_sub.html" );
79
+ assertThat (reader , is (notNullValue ()));
80
+ }
68
81
}
You can’t perform that action at this time.
0 commit comments