Skip to content

Commit 1734071

Browse files
committed
swagger-initializer.js is sent endcoded in the JVM's default charset.. Fixes #2207
1 parent 534ad5e commit 1734071

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

springdoc-openapi-common/src/test/java/org/springdoc/ui/AbstractSwaggerIndexTransformerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.ByteArrayInputStream;
44
import java.io.IOException;
55
import java.io.InputStream;
6+
import java.nio.charset.StandardCharsets;
67

78
import org.junit.jupiter.api.BeforeEach;
89
import org.junit.jupiter.api.Test;
@@ -48,7 +49,7 @@ public class AbstractSwaggerIndexTransformerTest {
4849
"\n" +
4950
" //</editor-fold>\n" +
5051
"};";
51-
private final InputStream is = new ByteArrayInputStream(swaggerInitJs.getBytes());
52+
private final InputStream is = new ByteArrayInputStream(swaggerInitJs.getBytes(StandardCharsets.UTF_8));
5253

5354
private final String apiDocUrl = "http://test.springdoc.com/apidoc";
5455

springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerIndexPageTransformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.springdoc.webmvc.ui;
2424

2525
import java.io.IOException;
26+
import java.nio.charset.StandardCharsets;
2627

2728
import javax.servlet.http.HttpServletRequest;
2829

@@ -75,7 +76,7 @@ public Resource transform(HttpServletRequest request, Resource resource,
7576

7677
if (isIndexFound) {
7778
String html = defaultTransformations(resource.getInputStream());
78-
return new TransformedResource(resource, html.getBytes());
79+
return new TransformedResource(resource, html.getBytes(StandardCharsets.UTF_8));
7980
}
8081
else
8182
return resource;

springdoc-openapi-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerIndexPageTransformer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
package org.springdoc.webflux.ui;
2424

25+
import java.nio.charset.StandardCharsets;
26+
2527
import org.springdoc.core.SwaggerUiConfigParameters;
2628
import org.springdoc.core.SwaggerUiConfigProperties;
2729
import org.springdoc.core.SwaggerUiOAuthProperties;
@@ -73,7 +75,7 @@ public Mono<Resource> transform(ServerWebExchange serverWebExchange, Resource re
7375
boolean isIndexFound = antPathMatcher.match("**/swagger-ui/**/" + SWAGGER_INITIALIZER_JS, resource.getURL().toString());
7476
if (isIndexFound) {
7577
String html = defaultTransformations(resource.getInputStream());
76-
return Mono.just(new TransformedResource(resource, html.getBytes()));
78+
return Mono.just(new TransformedResource(resource, html.getBytes(StandardCharsets.UTF_8)));
7779
}
7880
else {
7981
return Mono.just(resource);

0 commit comments

Comments
 (0)