File tree Expand file tree Collapse file tree 4 files changed +61
-9
lines changed
jooby-netty/src/main/java/io/jooby/internal/netty
jooby-utow/src/main/java/io/jooby/internal/utow Expand file tree Collapse file tree 4 files changed +61
-9
lines changed Original file line number Diff line number Diff line change @@ -533,6 +533,10 @@ private FileUpload register(FileUpload upload) {
533533 }
534534
535535 private void decodeForm (HttpRequest req , Formdata form ) {
536+ if (decoder == null ) {
537+ // empty/bad form
538+ return ;
539+ }
536540 try {
537541 while (decoder .hasNext ()) {
538542 HttpData next = (HttpData ) decoder .next ();
Original file line number Diff line number Diff line change @@ -398,15 +398,17 @@ void destroy(Exception cause) {
398398 }
399399
400400 private void formData (Formdata form , FormData data ) {
401- Iterator <String > it = data .iterator ();
402- while (it .hasNext ()) {
403- String path = it .next ();
404- Deque <FormData .FormValue > values = data .get (path );
405- for (FormData .FormValue value : values ) {
406- if (value .isFileItem ()) {
407- form .put (path , new UtowFileUpload (path , value ));
408- } else {
409- form .put (path , value .getValue ());
401+ if (data != null ) {
402+ Iterator <String > it = data .iterator ();
403+ while (it .hasNext ()) {
404+ String path = it .next ();
405+ Deque <FormData .FormValue > values = data .get (path );
406+ for (FormData .FormValue value : values ) {
407+ if (value .isFileItem ()) {
408+ form .put (path , new UtowFileUpload (path , value ));
409+ } else {
410+ form .put (path , value .getValue ());
411+ }
410412 }
411413 }
412414 }
Original file line number Diff line number Diff line change 175175 </execution >
176176 </executions >
177177 </plugin >
178+ <!-- sure-fire -->
179+ <plugin >
180+ <groupId >org.apache.maven.plugins</groupId >
181+ <artifactId >maven-surefire-plugin</artifactId >
182+ <configuration >
183+ <skip >false</skip >
184+ <includes >
185+ <include >**/*Test.java</include >
186+ <include >**/*Feature.java</include >
187+ <include >**/*Issue*.java</include >
188+ </includes >
189+ </configuration >
190+ </plugin >
178191 </plugins >
179192 </build >
180193
Original file line number Diff line number Diff line change 1+ package io .jooby ;
2+
3+ import org .junit .jupiter .api .DisplayName ;
4+ import org .junit .jupiter .api .Test ;
5+
6+ import static io .restassured .RestAssured .given ;
7+ import static org .hamcrest .Matchers .equalTo ;
8+ import static org .junit .jupiter .api .Assertions .assertEquals ;
9+
10+ public class Issue1338 {
11+ @ Test
12+ @ DisplayName ("Form should not fail when empty" )
13+ public void issue1338 () {
14+ new JoobyRunner (app -> {
15+ app .post ("/1338/form" , ctx -> ctx .form ().toMap ());
16+
17+ app .post ("/1338/multipart" , ctx -> ctx .form ().toMap ());
18+
19+ }).ready (client -> {
20+ client .post ("/1338/form" , rsp -> {
21+ assertEquals ("{}" , rsp .body ().string ());
22+ });
23+ given ()
24+ .port (client .getPort ())
25+ .contentType ("multipart/form-data;" )
26+ .when ()
27+ .post ("/1338/multipart" )
28+ .then ()
29+ .assertThat ()
30+ .body (equalTo ("{}" ));
31+ });
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments