[HtmlParser]bug提交(含解决方案)--A bug when set cookies

46 篇文章 0 订阅

htmlParser在设置cookies时存在bug,对于相同的domain,不能设置多个cookies.下面时偶提交的bug内容及解决办法.偶英语很烂--大家别笑话.:P

There can't set many cookies to a domain,for example:

public   void  testSetCookies()  throws  Exception
{
String urlString 
=   " http://sourceforge.net/projects/htmlparser " ;
Parser parser 
=   this .buildParser(urlString);

}

private  Parser buildParser(String urlString)  throws  
Exception
{
ConnectionManager manager 
=  
Parser.getConnectionManager ();
Cookie cookie 
=   new  Cookie ( " name1 " " value1 " );
manager.setCookie (cookie, 
" sourceforge.net " );

cookie 
=   new  Cookie ( " name2 " " value2 " );
manager.setCookie (cookie, 
" sourceforge.net " );

return   new  Parser(urlString);
}


only the first cookie was set to the
domain "sourceforge.net".

This bug comes with the
method:ConnectionManager.setCookie (Cookie cookie,
String domain),there can't add a new cookie to a exist
domain.

It is ok if repleace the method with under codes :

public   void  setCookie (Cookie cookie, String domain)
{
String path;
Vector cookies;
Cookie probe;

if  ( null   !=  cookie.getDomain ())
domain 
=  cookie.getDomain ();
path 
=  cookie.getPath ();
if  ( null   ==  mCookieJar)
mCookieJar 
=   new  Hashtable ();  //  turn on 
cookie processing
cookies 
=  (Vector)mCookieJar.get (domain);
if  ( null   !=  cookies)
{
boolean  isNewCookie  =   true ;

for  ( int  j  =   0 ; j  <  cookies.size (); j ++ )
{
probe 
=  (Cookie)cookies.elementAt (j);


if  (probe.getName ().equalsIgnoreCase 
(cookie.getName ()))
{
if (isNewCookie  ==   true ) isNewCookie  =  
false ;
//  we keep paths sorted most specific to 
least
if  (probe.getPath ().equals (path))
{
cookies.setElementAt (cookie, j); 
//  
replace
break ;
}
else   if  (path.startsWith (probe.getPath ()))
{
cookies.insertElementAt (cookie, j);
break ;
}
}
}

if (isNewCookie  ==   true )
{
cookies.addElement(cookie);
}
}
else
//  new cookie list needed
cookies  =   new  Vector ();
cookies.addElement (cookie);
mCookieJar.put (domain, cookies);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值