dIon Gillard wrote:
> Definitely. But the place it is breaking is on the compare, which is
> used for sorting the cookies. Should null always match a domain?
> Should it always be less than another domain? I need to think this one
> through.
Must be mad, replying to myself, but null domains will break the matches
method. So I think we need to fix a few things on the null side as well.
>> Perhaps we should add unit tests for processing null domains, paths,
>> etc.,
>> just to document this contract.
>>
> Definitely.
>
>> The typical browser behavior, which I think is specified by the old
>> "netscape" cookie spec, is to assume a default path of "/" and a default
>> domain of the full-specified domain used in the request. I'm pretty
>> sure
>> that's the behavior Cookie used to have.
>>
> Then we should probably codify this assumption, and in the get method
> for path, if the value is null, return "/".
>
>> - Rod
>
From the RFC "If multiple cookies satisfy the criteria above, they are
ordered in the Cookie header such that those with more specific Path
attributes precede those with less specific. Ordering with respect to
other attributes (e.g., Domain) is unspecified.". So given this, I I'll
change the compare method so it only uses path. My current version looks
like this:
if (!(o1 instanceof Cookie)) {
throw new ClassCastException(o1.getClass().getName());
}
if (!(o2 instanceof Cookie)) {
throw new ClassCastException(o2.getClass().getName());
}
Cookie c1 = (Cookie)o1;
Cookie c2 = (Cookie)o2;
if (c1.getPath() == null && c2.getPath() == null) {
return 0;
} else if (c1.getPath() == null) {
// null is assumed to be "/"
if (c2.getPath().equals("/")) {
return 0;
} else {
return -1;
}
} else if (c2.getPath() == null) {
if (c1.getPath().equals("/")) {
return 0;
} else {
return 1;
}
} else {
return stringCollator.compare(c1.getPath(), c2.getPath());
}
If this is ok, let me know and I'll commit it. We still need to fix null
domains, however.
I'll file this as a bug report.
--
dIon Gillard, Multitask Consulting
http://www.multitask.com.au/developers
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>