Forwarding to Classpath list for approval.
Andrew.
--- Begin Message ---
Howdy,
The full details about the two problems found in the libjava
java.net.URI.relativize method are described in the following bug
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34369 along with a provided
java based testcase and comparisons of results obtained with the same
testcase executed under three other Java VMs from Sun and IBM.
Basically, I made some minor changes to the method to improve the path
prefix checking over the simpler string matching that was producing some
false positives in some cases.
One change fixed a problem where a different path containing a URI with
a path that contained the same starting characters as another URI path.
For example, "file:/home/eclipse/runtime-New_configuration/simple" was
being incorrectly considered as a prefix of
"file:/home/eclipse/runtime-New_configuration/simple_spu/simple_spu.c".
The second change involved removing a leading '/' from the returned
relative path to make it consistent with results from other Java VMs.
This patch corrects two issues found in URI.relativize() method in
libjava/classpath/java/net/URI.java. It applies from gcc 4.1.2 through latest
trunk:
* does stricter check for a path match while still using String.startsWith()
* excludes leading '/' if necessary for relative path fragment being returned
--
Luciano Chavez <[EMAIL PROTECTED]>
IBM
Index: URI.java
===================================================================
--- URI.java (revision 130639)
+++ URI.java (working copy)
@@ -968,12 +968,19 @@
return uri;
if (rawAuthority != null && !(rawAuthority.equals(uri.getRawAuthority())))
return uri;
- if (!(uri.getRawPath().startsWith(rawPath)))
- return uri;
+ String basePath = new String(rawPath);
+ if (!(uri.getRawPath().equals(rawPath)))
+ {
+ if (!(rawPath.endsWith("/")))
+ basePath = rawPath.concat("/");
+
+ if (!(uri.getRawPath().startsWith(basePath)))
+ return uri;
+ }
try
{
return new URI(null, null,
- uri.getRawPath().substring(rawPath.length()),
+ uri.getRawPath().substring(basePath.length()),
uri.getRawQuery(), uri.getRawFragment());
}
catch (URISyntaxException e)
--- End Message ---
--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4
1TE, UK
Registered in England and Wales No. 3798903