11package org .jscookie .test .integration .encoding ;
22
33import java .io .IOException ;
4+ import java .io .UnsupportedEncodingException ;
5+ import java .net .URLDecoder ;
6+ import java .nio .charset .StandardCharsets ;
47
58import javax .servlet .ServletException ;
69import javax .servlet .annotation .WebServlet ;
@@ -18,7 +21,7 @@ public class EncodingServlet extends HttpServlet {
1821 @ Override
1922 public void doGet ( HttpServletRequest request , HttpServletResponse response )
2023 throws ServletException , IOException {
21- String name = request . getParameter ( "name" );
24+ String name = getUTF8Param ( "name" , request );
2225
2326 System .out .println ( "--------------------" );
2427 System .out .println ( "Testing: " + name );
@@ -39,6 +42,19 @@ public void doGet( HttpServletRequest request, HttpServletResponse response )
3942 new ObjectMapper ()
4043 .writeValue ( response .getOutputStream (), new Result ( name , value ) );
4144 }
45+
46+ /**
47+ * Retrieves the parameter using UTF-8 charset since the server default is ISO-8859-1
48+ */
49+ private String getUTF8Param ( String name , HttpServletRequest request ) throws UnsupportedEncodingException {
50+ String query = request .getQueryString ();
51+ for ( String pair : query .split ( "&" ) ) {
52+ if ( name .equals ( pair .split ( "=" )[ 0 ] ) ) {
53+ return URLDecoder .decode ( pair .split ( "=" )[ 1 ], StandardCharsets .UTF_8 .name () );
54+ }
55+ }
56+ return null ;
57+ }
4258}
4359
4460class Result {
0 commit comments