Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
85531fbd
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
85531fbd
编写于
12月 13, 2012
作者:
R
robm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8000525: Java.net.httpcookie api does not support 2-digit year format
Reviewed-by: chegar
上级
d15bbc7e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
125 addition
and
6 deletion
+125
-6
src/share/classes/java/net/HttpCookie.java
src/share/classes/java/net/HttpCookie.java
+24
-3
test/java/net/CookieHandler/B6791927.java
test/java/net/CookieHandler/B6791927.java
+2
-2
test/java/net/CookieHandler/CookieManagerTest.java
test/java/net/CookieHandler/CookieManagerTest.java
+1
-1
test/java/net/HttpCookie/ExpiredCookieTest.java
test/java/net/HttpCookie/ExpiredCookieTest.java
+98
-0
未找到文件。
src/share/classes/java/net/HttpCookie.java
浏览文件 @
85531fbd
...
...
@@ -30,6 +30,8 @@ import java.util.StringTokenizer;
import
java.util.NoSuchElementException
;
import
java.text.SimpleDateFormat
;
import
java.util.TimeZone
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.Date
;
import
java.util.Locale
;
import
java.util.Objects
;
...
...
@@ -89,7 +91,10 @@ public final class HttpCookie implements Cloneable {
private
final
static
String
[]
COOKIE_DATE_FORMATS
=
{
"EEE',' dd-MMM-yyyy HH:mm:ss 'GMT'"
,
"EEE',' dd MMM yyyy HH:mm:ss 'GMT'"
,
"EEE MMM dd yyyy HH:mm:ss 'GMT'Z"
"EEE MMM dd yyyy HH:mm:ss 'GMT'Z"
,
"EEE',' dd-MMM-yy HH:mm:ss 'GMT'"
,
"EEE',' dd MMM yy HH:mm:ss 'GMT'"
,
"EEE MMM dd yy HH:mm:ss 'GMT'Z"
};
// constant strings represent set-cookie header token
...
...
@@ -1025,13 +1030,29 @@ public final class HttpCookie implements Cloneable {
* specified by dateString
*/
private
long
expiryDate2DeltaSeconds
(
String
dateString
)
{
Calendar
cal
=
new
GregorianCalendar
(
GMT
);
for
(
int
i
=
0
;
i
<
COOKIE_DATE_FORMATS
.
length
;
i
++)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
COOKIE_DATE_FORMATS
[
i
],
Locale
.
US
);
cal
.
set
(
1970
,
0
,
1
,
0
,
0
,
0
);
df
.
setTimeZone
(
GMT
);
df
.
setLenient
(
false
);
df
.
set2DigitYearStart
(
cal
.
getTime
());
try
{
Date
date
=
df
.
parse
(
dateString
);
return
(
date
.
getTime
()
-
whenCreated
)
/
1000
;
cal
.
setTime
(
df
.
parse
(
dateString
));
if
(!
COOKIE_DATE_FORMATS
[
i
].
contains
(
"yyyy"
))
{
// 2-digit years following the standard set
// out it rfc 6265
int
year
=
cal
.
get
(
Calendar
.
YEAR
);
year
%=
100
;
if
(
year
<
70
)
{
year
+=
2000
;
}
else
{
year
+=
1900
;
}
cal
.
set
(
Calendar
.
YEAR
,
year
);
}
return
(
cal
.
getTimeInMillis
()
-
whenCreated
)
/
1000
;
}
catch
(
Exception
e
)
{
// Ignore, try the next date format
}
...
...
test/java/net/CookieHandler/B6791927.java
浏览文件 @
85531fbd
/*
* Copyright (c) 2009, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 201
2
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -37,7 +37,7 @@ public class B6791927 {
try
{
// Forces a non US locale
Locale
.
setDefault
(
Locale
.
FRANCE
);
List
<
HttpCookie
>
cookies
=
HttpCookie
.
parse
(
"set-cookie: CUSTOMER=WILE_E_COYOTE; expires=
Wednesday
, 09-Nov-2019 23:12:40 GMT"
);
List
<
HttpCookie
>
cookies
=
HttpCookie
.
parse
(
"set-cookie: CUSTOMER=WILE_E_COYOTE; expires=
Sat
, 09-Nov-2019 23:12:40 GMT"
);
if
(
cookies
==
null
||
cookies
.
isEmpty
())
{
throw
new
RuntimeException
(
"No cookie found"
);
}
...
...
test/java/net/CookieHandler/CookieManagerTest.java
浏览文件 @
85531fbd
...
...
@@ -126,7 +126,7 @@ class CookieHttpTransaction implements HttpCallback {
testPolicies
[
count
]
=
CookiePolicy
.
ACCEPT_ORIGINAL_SERVER
;
testCases
[
count
++]
=
new
CookieTestCase
[]{
new
CookieTestCase
(
"Set-Cookie"
,
"CUSTOMER=WILE:BOB; path=/; expires=
Wednesday
, 09-Nov-2030 23:12:40 GMT;"
+
"domain=."
+
localHostAddr
,
"CUSTOMER=WILE:BOB; path=/; expires=
Sat
, 09-Nov-2030 23:12:40 GMT;"
+
"domain=."
+
localHostAddr
,
"CUSTOMER=WILE:BOB"
,
"/"
),
...
...
test/java/net/HttpCookie/ExpiredCookieTest.java
0 → 100644
浏览文件 @
85531fbd
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8000525
*/
import
java.net.*
;
import
java.util.*
;
import
java.io.*
;
import
java.text.*
;
public
class
ExpiredCookieTest
{
// lifted from HttpCookie.java
private
final
static
String
[]
COOKIE_DATE_FORMATS
=
{
"EEE',' dd-MMM-yy HH:mm:ss 'GMT'"
,
"EEE',' dd MMM yy HH:mm:ss 'GMT'"
,
"EEE MMM dd yy HH:mm:ss 'GMT'Z"
,
"EEE',' dd-MMM-yyyy HH:mm:ss 'GMT'"
,
"EEE',' dd MMM yyyy HH:mm:ss 'GMT'"
,
"EEE MMM dd yyyy HH:mm:ss 'GMT'Z"
};
static
final
TimeZone
GMT
=
TimeZone
.
getTimeZone
(
"GMT"
);
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Calendar
cal
=
Calendar
.
getInstance
(
GMT
);
for
(
int
i
=
0
;
i
<
COOKIE_DATE_FORMATS
.
length
;
i
++)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
COOKIE_DATE_FORMATS
[
i
],
Locale
.
US
);
cal
.
set
(
1970
,
0
,
1
,
0
,
0
,
0
);
df
.
setTimeZone
(
GMT
);
df
.
setLenient
(
false
);
df
.
set2DigitYearStart
(
cal
.
getTime
());
CookieManager
cm
=
new
CookieManager
(
null
,
CookiePolicy
.
ACCEPT_ALL
);
CookieHandler
.
setDefault
(
cm
);
Map
<
String
,
List
<
String
>>
header
=
new
HashMap
<>();
List
<
String
>
values
=
new
ArrayList
<>();
cal
.
set
(
1970
,
6
,
9
,
10
,
10
,
1
);
StringBuilder
datestring
=
new
StringBuilder
(
df
.
format
(
cal
.
getTime
()));
values
.
add
(
"TEST1=TEST1; Path=/; Expires="
+
datestring
.
toString
());
cal
.
set
(
1969
,
6
,
9
,
10
,
10
,
2
);
datestring
=
new
StringBuilder
(
df
.
format
(
cal
.
getTime
()));
values
.
add
(
"TEST2=TEST2; Path=/; Expires="
+
datestring
.
toString
());
cal
.
set
(
2070
,
6
,
9
,
10
,
10
,
3
);
datestring
=
new
StringBuilder
(
df
.
format
(
cal
.
getTime
()));
values
.
add
(
"TEST3=TEST3; Path=/; Expires="
+
datestring
.
toString
());
cal
.
set
(
2069
,
6
,
9
,
10
,
10
,
4
);
datestring
=
new
StringBuilder
(
df
.
format
(
cal
.
getTime
()));
values
.
add
(
"TEST4=TEST4; Path=/; Expires="
+
datestring
.
toString
());
header
.
put
(
"Set-Cookie"
,
values
);
cm
.
put
(
new
URI
(
"http://127.0.0.1/"
),
header
);
CookieStore
cookieJar
=
cm
.
getCookieStore
();
List
<
HttpCookie
>
cookies
=
cookieJar
.
getCookies
();
if
(
COOKIE_DATE_FORMATS
[
i
].
contains
(
"yyyy"
))
{
if
(
cookies
.
size
()
!=
2
)
throw
new
RuntimeException
(
"Incorrectly parsing a bad date"
);
}
else
if
(
cookies
.
size
()
!=
1
)
{
throw
new
RuntimeException
(
"Incorrectly parsing a bad date"
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录