|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.web;
|
18 | 18 |
|
| 19 | +import static org.junit.Assert.assertTrue; |
| 20 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 21 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 22 | + |
19 | 23 | import java.lang.annotation.Documented;
|
20 | 24 | import java.lang.annotation.ElementType;
|
21 | 25 | import java.lang.annotation.Retention;
|
|
41 | 45 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
42 | 46 | import org.springframework.web.context.WebApplicationContext;
|
43 | 47 |
|
44 |
| -import static org.junit.Assert.assertTrue; |
45 |
| -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
46 |
| -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
47 |
| - |
48 | 48 | /**
|
49 | 49 | * @author Dave Syer
|
50 | 50 | */
|
@@ -74,6 +74,22 @@ public void testErrorForBrowserClient() throws Exception {
|
74 | 74 | assertTrue("Wrong content: " + content, content.contains("999"));
|
75 | 75 | }
|
76 | 76 |
|
| 77 | + @Test |
| 78 | + public void testErrorWithEscape() throws Exception { |
| 79 | + MvcResult response = this.mockMvc |
| 80 | + .perform( |
| 81 | + get("/error").requestAttr( |
| 82 | + "javax.servlet.error.exception", |
| 83 | + new RuntimeException( |
| 84 | + "<script>alert('Hello World')</script>")).accept( |
| 85 | + MediaType.TEXT_HTML)).andExpect(status().isOk()) |
| 86 | + .andReturn(); |
| 87 | + String content = response.getResponse().getContentAsString(); |
| 88 | + assertTrue("Wrong content: " + content, content.contains("<script>")); |
| 89 | + assertTrue("Wrong content: " + content, content.contains("Hello World")); |
| 90 | + assertTrue("Wrong content: " + content, content.contains("999")); |
| 91 | + } |
| 92 | + |
77 | 93 | @Target(ElementType.TYPE)
|
78 | 94 | @Retention(RetentionPolicy.RUNTIME)
|
79 | 95 | @Documented
|
|
0 commit comments