D
Dan Ruehle
I believe I have found a bug in the Uri class. I believe it is incorrectly
removing periods that appear at the end of segments in the path. The
following code shows what I mean:
public void TestUriAndPeriods()
{
const string urlWithoutPeriod =
"http://my.domain.com/top.level.folder/top.level.folder/my.cool.picture.jpg";
const string urlWithPeriod =
"http://my.domain.com/top.level.folder/top.level.folder./my.cool.picture.jpg";
Uri uriWithoutPeriod = new Uri(urlWithoutPeriod);
Uri uriWithPeriod = new Uri(urlWithPeriod);
if (uriWithoutPeriod.ToString() == uriWithPeriod.ToString())
{
throw new ApplicationException("These Uri's should NOT be equal ");
}
}
The Uri class removes the period at the end of the "second.level.folder."
segment of the path. Per RFC 2396 <http://www.ietf.org/rfc/rfc2396.txt>,
the "./" should only be removed where "." is a complete path segment. Since
it is not in this scenario, it should not be removed.
Normally, this would not be a problem, however I have an application where
customers can provide Uri's to download content. We have some customers
that use Apache and they are somehow generating Uri's that have this
scenario and we have no way to actually hit these Uri's via .Net. Of
course, they respond incorrectly to these requests by returning a zero byte
response body with a 200 HTTP response, but that is another matter for our
customer. Putting the same Uri in IE 7 or FireFox 3 works fine.
I have attempted encoding the period as %2e and that does not seem to help
at all. It just converts it to a period and removes it.
The only workaround I can think of right now means rewriting the WebRequest
and associated classes to manage the underlying TCP connection as they all
utilize the Uri class even when passing in a string to the static creator.
I'd really rather to not have to do this.
Any ideas would be greatly appreciated.
removing periods that appear at the end of segments in the path. The
following code shows what I mean:
public void TestUriAndPeriods()
{
const string urlWithoutPeriod =
"http://my.domain.com/top.level.folder/top.level.folder/my.cool.picture.jpg";
const string urlWithPeriod =
"http://my.domain.com/top.level.folder/top.level.folder./my.cool.picture.jpg";
Uri uriWithoutPeriod = new Uri(urlWithoutPeriod);
Uri uriWithPeriod = new Uri(urlWithPeriod);
if (uriWithoutPeriod.ToString() == uriWithPeriod.ToString())
{
throw new ApplicationException("These Uri's should NOT be equal ");
}
}
The Uri class removes the period at the end of the "second.level.folder."
segment of the path. Per RFC 2396 <http://www.ietf.org/rfc/rfc2396.txt>,
the "./" should only be removed where "." is a complete path segment. Since
it is not in this scenario, it should not be removed.
Normally, this would not be a problem, however I have an application where
customers can provide Uri's to download content. We have some customers
that use Apache and they are somehow generating Uri's that have this
scenario and we have no way to actually hit these Uri's via .Net. Of
course, they respond incorrectly to these requests by returning a zero byte
response body with a 200 HTTP response, but that is another matter for our
customer. Putting the same Uri in IE 7 or FireFox 3 works fine.
I have attempted encoding the period as %2e and that does not seem to help
at all. It just converts it to a period and removes it.
The only workaround I can think of right now means rewriting the WebRequest
and associated classes to manage the underlying TCP connection as they all
utilize the Uri class even when passing in a string to the static creator.
I'd really rather to not have to do this.
Any ideas would be greatly appreciated.