Though I agree this seems a little strange I am not sure it's a bug. URI.normalize() is using the algorithm defined at <http://www.apache.org/~fielding/uri/rev-2002/issues.html> which corresponds to the latest update(I believe) to rfc2396. This algorithm is defined below.

1) The buffer is initialized with the unprocessed path component.

2) If the buffer begins with "./" or "../", the "." or ".." segment is removed.

3) All occurrences of "/./" in the buffer are replaced with "/".

4) If the buffer ends with "/.", the "." is removed.

5) All occurrences of "/<segment>/../" in the buffer, where ".." and <segment> are complete path segments, are iteratively replaced with "/" in order from left to right until no matching pattern remains. If the buffer ends with "/<segment>/..", that is also replaced with "/". Note that <segment> may be empty.

6) All prefixes of "<segment>/../" in the buffer, where ".." and <segment> are complete path segments, are iteratively replaced with "/" in order from left to right until no matching pattern remains. If the buffer ends with "<segment>/..", that is also replaced with "/". Note that <segment> may be empty.

7) The remaining buffer is returned as the result of remove_dot_segments.


This algorithm results in the following process:


# at rule 1
buffer = "my/relative/../../another/relative"

# rules 2, 3 and 4 are ignored

# rule 5 is applied once and "/relative/../" is replaced with "/"
buffer = "my/../another/relative"

# rule 6 is applied once and "my/../" is replaced with "/"
buffer = "/another/relative"


And we're done. Perhaps we should send and email to [EMAIL PROTECTED] and see if they have any input. Does anyone else have an opinion about this?


Mike


Marcus Crafter wrote:
Hi All,

Hope all is well. I have a question to do with normalizing a URI with
..'s in it.

If I execute the following code:

URI u = new URI("my/relative/../../another/relative");
u.normalize();
u.getURI();

should the URI now be /another/relative or 'another/relative'

The code returns /another/relative but I was actually expecting 'another/relative' since the original URI was without a leading /.

Was my expectation wrong or could this be a defect? Any ideas?

Cheers,

Marcus





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to