File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed
main/java/io/github/easybill/xrviz/handler Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,14 @@ Optional<String> validate(HttpExchange exchange) throws IOException {
32
32
String encoding = detector .getDetectedCharset ();
33
33
detector .reset ();
34
34
35
- // Fallback to UTF-8 if no encoding was detected
36
- Charset charset = (encoding != null ) ? Charset .forName (encoding ) : StandardCharsets .UTF_8 ;
35
+ Charset charset = null ;
36
+ try {
37
+ charset = (encoding != null ) ? Charset .forName (encoding ) : StandardCharsets .UTF_8 ;
38
+ } catch (IllegalArgumentException e ) {
39
+ logger .severe ("Invalid charset: " + encoding );
40
+ exchange .sendResponseHeaders (HttpURLConnection .HTTP_BAD_REQUEST , -1 );
41
+ return Optional .empty ();
42
+ }
37
43
38
44
String xml = new String (requestBody , charset );
39
45
Original file line number Diff line number Diff line change @@ -87,3 +87,10 @@ Content-Type: application/xml
87
87
Accept-Language: de
88
88
89
89
< ./base-example-utf16le.xml
90
+
91
+ ### Generate a HTML file from a XML with broken encoding
92
+ POST {{baseUrl }}/convert.html
93
+ Content-Type: application/xml
94
+ Accept-Language: de
95
+
96
+ < ./broken-encoding.xml
You can’t perform that action at this time.
0 commit comments