Skip to content

Commit a733ae1

Browse files
committed
build: fix windows OS failing test
1 parent 0a9e359 commit a733ae1

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoaderTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package com.github.jknack.handlebars.springmvc;
77

88
import static org.junit.jupiter.api.Assertions.*;
9-
import static org.mockito.ArgumentMatchers.anyString;
109
import static org.mockito.Mockito.mock;
1110
import static org.mockito.Mockito.when;
1211

@@ -75,14 +74,15 @@ public void shouldBlockUrlFragmentInjection() throws IOException {
7574
URL maliciousUrl = new URL("file:///etc/passwd#.hbs");
7675
when(mockResource.getURL()).thenReturn(maliciousUrl);
7776

78-
// We must mock the exact string that the template loader will ask Spring for
79-
when(resourceLoader.getResource(anyString())).thenReturn(mockResource);
77+
// Mock the exact valid string Handlebars will request after prefix/suffix append
78+
when(resourceLoader.getResource("classpath:/templates/hack.hbs")).thenReturn(mockResource);
8079

8180
IllegalArgumentException exception =
8281
assertThrows(
8382
IllegalArgumentException.class,
8483
() -> {
85-
templateLoader.sourceAt("classpath:/templates/hack#.hbs");
84+
// Pass a clean string to bypass OS-level Paths.get() restrictions
85+
templateLoader.sourceAt("hack");
8686
});
8787

8888
assertTrue(exception.getMessage().contains("Template URL must not contain a fragment"));
@@ -97,13 +97,15 @@ public void shouldBlockUrlQueryInjection() throws IOException {
9797
URL maliciousUrl = new URL("file:///etc/passwd?.hbs");
9898
when(mockResource.getURL()).thenReturn(maliciousUrl);
9999

100-
when(resourceLoader.getResource(anyString())).thenReturn(mockResource);
100+
// Mock the exact valid string Handlebars will request after prefix/suffix append
101+
when(resourceLoader.getResource("classpath:/templates/hack.hbs")).thenReturn(mockResource);
101102

102103
IllegalArgumentException exception =
103104
assertThrows(
104105
IllegalArgumentException.class,
105106
() -> {
106-
templateLoader.sourceAt("classpath:/templates/hack?.hbs");
107+
// Pass a clean string to bypass OS-level Paths.get() restrictions
108+
templateLoader.sourceAt("hack");
107109
});
108110

109111
assertTrue(exception.getMessage().contains("Template URL must not contain a query"));

0 commit comments

Comments
 (0)