P
Peter Davis
I'm trying to figure something out -- java.net.URI.equals() makes no
sense the way it is specified:
"When testing the user-information, path, query, fragment, authority,
or scheme-specific parts of two URIs for equality, the raw forms rather
than the encoded forms of these components are compared and the
hexadecimal digits of escaped octets are compared without regard to
case."
First of all, is that a typo? I think it's trying to say "the raw
forms rather than the /decoded/ forms...". Aside from that, the
problem is that it would make sense if two URIs with encoded or
unencoded versions of the same characters should be equal, but they're
not. I wrote a little test class:
import java.net.*;
class Test {
public static void main(String[] args) throws Throwable {
URI u1 = new URI("foo%7Ebar");
URI u2 = new URI("foo%7ebar");
URI u3 = new URI("foo~bar");
System.out.println(u1 + " == " + u2 + " => " + u1.equals(u2));
System.out.println(u1 + " == " + u3 + " => " + u1.equals(u3));
System.out.println(u2 + " == " + u3 + " => " + u2.equals(u3));
}
}
Outputs:
foo%7Ebar == foo%7ebar => true
foo%7Ebar == foo~bar => false
foo%7ebar ==foo~bar => false
Why in the world would it compare the raw rather than decoded forms of
the URI? Anybody have any clues?
sense the way it is specified:
"When testing the user-information, path, query, fragment, authority,
or scheme-specific parts of two URIs for equality, the raw forms rather
than the encoded forms of these components are compared and the
hexadecimal digits of escaped octets are compared without regard to
case."
First of all, is that a typo? I think it's trying to say "the raw
forms rather than the /decoded/ forms...". Aside from that, the
problem is that it would make sense if two URIs with encoded or
unencoded versions of the same characters should be equal, but they're
not. I wrote a little test class:
import java.net.*;
class Test {
public static void main(String[] args) throws Throwable {
URI u1 = new URI("foo%7Ebar");
URI u2 = new URI("foo%7ebar");
URI u3 = new URI("foo~bar");
System.out.println(u1 + " == " + u2 + " => " + u1.equals(u2));
System.out.println(u1 + " == " + u3 + " => " + u1.equals(u3));
System.out.println(u2 + " == " + u3 + " => " + u2.equals(u3));
}
}
Outputs:
foo%7Ebar == foo%7ebar => true
foo%7Ebar == foo~bar => false
foo%7ebar ==foo~bar => false
Why in the world would it compare the raw rather than decoded forms of
the URI? Anybody have any clues?