File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed
main/java/org/springframework/util
test/java/org/springframework/util
main/java/org/springframework/http
test/java/org/springframework/http Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 38
38
* @author Arjen Poutsma
39
39
* @author Rossen Stoyanchev
40
40
* @author Dimitrios Liapis
41
+ * @author Sam Brannen
41
42
* @since 4.0
42
43
*/
43
44
public abstract class MimeTypeUtils {
@@ -259,10 +260,11 @@ public static List<MimeType> parseMimeTypes(String mimeTypes) {
259
260
return Collections .emptyList ();
260
261
}
261
262
return tokenize (mimeTypes ).stream ()
262
- .map (MimeTypeUtils ::parseMimeType ).collect (Collectors .toList ());
263
+ .filter (StringUtils ::hasText )
264
+ .map (MimeTypeUtils ::parseMimeType )
265
+ .collect (Collectors .toList ());
263
266
}
264
267
265
-
266
268
/**
267
269
* Tokenize the given comma-separated string of {@code MimeType} objects
268
270
* into a {@code List<String>}. Unlike simple tokenization by ",", this
Original file line number Diff line number Diff line change @@ -277,6 +277,13 @@ public void parseMimeTypes() {
277
277
assertEquals ("Invalid amount of mime types" , 0 , mimeTypes .size ());
278
278
}
279
279
280
+ @ Test // gh-23241
281
+ public void parseMimeTypesWithTrailingComma () {
282
+ List <MimeType > mimeTypes = MimeTypeUtils .parseMimeTypes ("text/plain, text/html," );
283
+ assertNotNull ("No mime types returned" , mimeTypes );
284
+ assertEquals ("Incorrect number of mime types" , 2 , mimeTypes .size ());
285
+ }
286
+
280
287
@ Test // SPR-17459
281
288
public void parseMimeTypesWithQuotedParameters () {
282
289
testWithQuotedParameters ("foo/bar;param=\" ,\" " );
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
44
44
* @author Rossen Stoyanchev
45
45
* @author Sebastien Deleuze
46
46
* @author Kazuki Shimizu
47
+ * @author Sam Brannen
47
48
* @since 3.0
48
49
* @see <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">
49
50
* HTTP 1.1: Semantics and Content, section 3.1.1.1</a>
@@ -553,7 +554,9 @@ public static List<MediaType> parseMediaTypes(@Nullable String mediaTypes) {
553
554
return Collections .emptyList ();
554
555
}
555
556
return MimeTypeUtils .tokenize (mediaTypes ).stream ()
556
- .map (MediaType ::parseMediaType ).collect (Collectors .toList ());
557
+ .filter (StringUtils ::hasText )
558
+ .map (MediaType ::parseMediaType )
559
+ .collect (Collectors .toList ());
557
560
}
558
561
559
562
/**
Original file line number Diff line number Diff line change @@ -143,6 +143,13 @@ public void parseMediaTypes() throws Exception {
143
143
assertEquals ("Invalid amount of media types" , 0 , mediaTypes .size ());
144
144
}
145
145
146
+ @ Test // gh-23241
147
+ public void parseMediaTypesWithTrailingComma () {
148
+ List <MediaType > mediaTypes = MediaType .parseMediaTypes ("text/plain, text/html, " );
149
+ assertNotNull ("No media types returned" , mediaTypes );
150
+ assertEquals ("Incorrect number of media types" , 2 , mediaTypes .size ());
151
+ }
152
+
146
153
@ Test
147
154
public void compareTo () {
148
155
MediaType audioBasic = new MediaType ("audio" , "basic" );
You can’t perform that action at this time.
0 commit comments