Fix corrupted saml2 metadata when special characters are present
Closes gh-13776
This commit is contained in:
parent
ac04c2e675
commit
b67218c150
|
@ -104,7 +104,7 @@ public final class Saml2MetadataFilter extends OncePerRequestFilter {
|
||||||
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
|
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
|
||||||
String format = "attachment; filename=\"%s\"; filename*=UTF-8''%s";
|
String format = "attachment; filename=\"%s\"; filename*=UTF-8''%s";
|
||||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format(format, fileName, encodedFileName));
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format(format, fileName, encodedFileName));
|
||||||
response.setContentLength(metadata.length());
|
response.setContentLength(metadata.getBytes(StandardCharsets.UTF_8).length);
|
||||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
response.getWriter().write(metadata);
|
response.getWriter().write(metadata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,6 +166,8 @@ public class Saml2MetadataFilterTests {
|
||||||
this.filter.doFilter(this.request, this.response, this.chain);
|
this.filter.doFilter(this.request, this.response, this.chain);
|
||||||
assertThat(this.response.getCharacterEncoding()).isEqualTo(StandardCharsets.UTF_8.name());
|
assertThat(this.response.getCharacterEncoding()).isEqualTo(StandardCharsets.UTF_8.name());
|
||||||
assertThat(this.response.getContentAsString(StandardCharsets.UTF_8)).isEqualTo(generatedMetadata);
|
assertThat(this.response.getContentAsString(StandardCharsets.UTF_8)).isEqualTo(generatedMetadata);
|
||||||
|
assertThat(this.response.getContentLength()).isEqualTo(
|
||||||
|
generatedMetadata.getBytes(StandardCharsets.UTF_8).length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue