allthingssecurity commented on code in PR #27851:
URL: https://github.com/apache/camel/pull/27851#discussion_r4277861095


##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowFormCharsetTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.undertow;
+
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.Map;
+
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Form fields are decoded as UTF-8 when the request does not declare a 
charset, as a browser sends them.
+ */
+class UndertowFormCharsetTest extends BaseUndertowTest {
+
+    private static final String TEXT = "Grüße";
+    private static final String BOUNDARY = "r27boundary";
+
+    @Test
+    void testUrlEncodedFormWithoutCharsetIsUtf8() throws Exception {
+        Message received = post("application/x-www-form-urlencoded", 
"name=Gr%C3%BC%C3%9Fe".getBytes(UTF_8));
+
+        assertEquals(TEXT, received.getHeader("name"));
+        assertEquals(TEXT, received.getBody(Map.class).get("name"));
+    }
+
+    @Test
+    void testMultipartTextFieldWithoutCharsetIsUtf8() throws Exception {
+        String multipart = "--" + BOUNDARY + "\r\n"
+                           + "Content-Disposition: form-data; 
name=\"name\"\r\n\r\n"
+                           + TEXT + "\r\n"
+                           + "--" + BOUNDARY + "--\r\n";
+        Message received = post("multipart/form-data; boundary=" + BOUNDARY, 
multipart.getBytes(UTF_8));
+
+        assertEquals(TEXT, received.getHeader("name"));
+        assertEquals(TEXT, received.getBody(Map.class).get("name"));
+    }
+
+    @Test
+    void testUrlEncodedFormKeepsDeclaredCharset() throws Exception {
+        // a charset that the request declares is still used
+        Message received = post("application/x-www-form-urlencoded; 
charset=ISO-8859-1",
+                ("name=" + TEXT).getBytes(ISO_8859_1));

Review Comment:
   Done in 05db3c29658b: the test now sends `name=Gr%FC%DFe` with 
`charset=ISO-8859-1` declared, like the other tests, and still expects `Grüße`. 
`UndertowFormCharsetTest`: 4 tests, 0 failures.
   
   _Claude Code on behalf of allthingssecurity_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to