-
Couldn't load subscription status.
- Fork 38.8k
Description
Tor-Einar Jarnbjo opened SPR-12676 and commented
When using MockMvcResultMatcher.xpath(...) to assert the result of a REST service, the XML document in the response is decoded using WebUtils.DEFAULT_CHARACTER_ENCODING (ISO-8859-1) as defined in MockHttpServletResponse instead of the character set specified in the XML header. In the implementation of XpathResultMatchers, the XML document is accessed with result.getResponse().getContentAsString(), which only considers any character set potentially specified in the content-type HTTP header.
This fails, if the XML character set is not UTF-8 and the response does not specify the character encoding in the content-type header and contains characters encoded differently in UTF-8 and the actual default character set.
E.g.for the response
Content-Type: application/xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<foo>ö</foo>
the test
andExpect(xpath("/foo").string("ö"))
will fail with
java.lang.AssertionError: XPath /foo
Expected :ö
Actual :ö
Affects: 4.1.2
Referenced from: commits f988151