Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d0893c42
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d0893c42
编写于
10月 27, 2009
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-6247 - Multipart Content-Type charset is ignored in CommonsFileUploadSupport.
上级
d54a975a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
4 deletion
+26
-4
org.springframework.web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java
...ework/web/multipart/commons/CommonsFileUploadSupport.java
+15
-3
org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java
...rc/test/java/org/springframework/http/MediaTypeTests.java
+10
-0
org.springframework.web/src/test/java/org/springframework/web/multipart/commons/CommonsMultipartResolverTests.java
.../web/multipart/commons/CommonsMultipartResolverTests.java
+1
-1
未找到文件。
org.springframework.web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java
浏览文件 @
d0893c42
...
...
@@ -22,6 +22,7 @@ import java.util.Collection;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.nio.charset.Charset
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.FileItemFactory
;
...
...
@@ -36,6 +37,7 @@ import org.springframework.util.MultiValueMap;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.util.WebUtils
;
import
org.springframework.http.MediaType
;
/**
* Base class for multipart resolvers that use Jakarta Commons FileUpload
...
...
@@ -221,14 +223,15 @@ public abstract class CommonsFileUploadSupport {
for
(
FileItem
fileItem
:
fileItems
)
{
if
(
fileItem
.
isFormField
())
{
String
value
;
if
(
encoding
!=
null
)
{
String
partEncoding
=
determineEncoding
(
fileItem
.
getContentType
(),
encoding
);
if
(
partEncoding
!=
null
)
{
try
{
value
=
fileItem
.
getString
(
e
ncoding
);
value
=
fileItem
.
getString
(
partE
ncoding
);
}
catch
(
UnsupportedEncodingException
ex
)
{
if
(
logger
.
isWarnEnabled
())
{
logger
.
warn
(
"Could not decode multipart item '"
+
fileItem
.
getFieldName
()
+
"' with encoding '"
+
e
ncoding
+
"': using platform default"
);
"' with encoding '"
+
partE
ncoding
+
"': using platform default"
);
}
value
=
fileItem
.
getString
();
}
...
...
@@ -281,6 +284,15 @@ public abstract class CommonsFileUploadSupport {
}
}
private
String
determineEncoding
(
String
contentTypeHeader
,
String
defaultEncoding
)
{
if
(!
StringUtils
.
hasText
(
contentTypeHeader
))
{
return
defaultEncoding
;
}
MediaType
contentType
=
MediaType
.
parseMediaType
(
contentTypeHeader
);
Charset
charset
=
contentType
.
getCharSet
();
return
charset
!=
null
?
charset
.
name
()
:
defaultEncoding
;
}
/**
* Holder for a Map of Spring MultipartFiles and a Map of
...
...
org.springframework.web/src/test/java/org/springframework/http/MediaTypeTests.java
浏览文件 @
d0893c42
...
...
@@ -19,6 +19,7 @@ package org.springframework.http;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.nio.charset.Charset
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
...
...
@@ -55,6 +56,15 @@ public class MediaTypeTests {
assertEquals
(
"Invalid quality factor"
,
0.2
D
,
mediaType
.
getQualityValue
(),
0
D
);
}
@Test
public
void
parseCharset
()
throws
Exception
{
String
s
=
"text/html; charset=iso-8859-1"
;
MediaType
mediaType
=
MediaType
.
parseMediaType
(
s
);
assertEquals
(
"Invalid type"
,
"text"
,
mediaType
.
getType
());
assertEquals
(
"Invalid subtype"
,
"html"
,
mediaType
.
getSubtype
());
assertEquals
(
"Invalid charset"
,
Charset
.
forName
(
"ISO-8859-1"
),
mediaType
.
getCharSet
());
}
@Test
public
void
parseURLConnectionMediaType
()
throws
Exception
{
String
s
=
"*; q=.2"
;
...
...
org.springframework.web/src/test/java/org/springframework/web/multipart/commons/CommonsMultipartResolverTests.java
浏览文件 @
d0893c42
...
...
@@ -375,7 +375,7 @@ public class CommonsMultipartResolverTests {
MockFileItem
fileItem2x
=
new
MockFileItem
(
"field2x"
,
"type2"
,
empty
?
""
:
"C:\\field2x.txt"
,
empty
?
""
:
"text2"
);
MockFileItem
fileItem3
=
new
MockFileItem
(
"field3"
,
null
,
null
,
"value3"
);
MockFileItem
fileItem4
=
new
MockFileItem
(
"field4"
,
null
,
null
,
"value4"
);
MockFileItem
fileItem4
=
new
MockFileItem
(
"field4"
,
"text/html; charset=iso-8859-1"
,
null
,
"value4"
);
MockFileItem
fileItem5
=
new
MockFileItem
(
"field4"
,
null
,
null
,
"value5"
);
fileItems
.
add
(
fileItem1
);
fileItems
.
add
(
fileItem1x
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录