Relative URI parsing

P

Paul Hatcher

I'm trying to test some functionality regarding relative URI's with the Uri
class in .NET 1.1 and hitting problems. The Uri class can only hold absolute
URIs, so there's a constructor that takes a URI and a string which is the
relative address.

However, some of the normative examples given in RFC 3986
(http://www.gbiv.com/protocols/uri/rfc/rfc3986.html) don't seem to be
handled by the class or give incorrect results.

For example, given a base address of http://a/b/c/d;p?q, the failing
normative examples are as follows...

"g:h" = "g:h" =>
System.UriFormatException : Invalid URI: The format of the URI could not be
determined
"//g" = "http://g" => http://g/ - Note
trailing /
"#s" = http://a/b/c/d;p?q#s => http://a/b/c/d;p#s
"../../../g" = http://a/g => http://a/../g
"../../../../g" = http://a/g => http://a/../../g
"/../g" = "http://a/g" => http://a/../g

Is this expected behaviour?

Paul
 
Y

Yuan Ren[MSFT]

Hi Paul,

Welcome to MSDN newsgroup!

As the MSDN document's description, if the UriFormatException has been
thrown, it means the format for URI is invalid which is defined in RFC 2396.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemuriformatexceptionclasstopic.asp

Currently, I'm not very clear about your problem. Could please the context
of the current issue? I means some snippet of your code. It will help me to
understand your problem well. Thanks for your understanding, I'm looking
forward your reply!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 
P

Paul Hatcher

Yuan

Ah, it's implementing an earlier version of the RFC for URI than I was
expecting; the latest is 3986, but as I was only published in Jan 2005 I can
see why Net 1.1 wouldn't have it :) The differences are mainly that the
authority component is optional, and that a relative reference can't
abstract away the authority component only the path, hence the differences
in the test results.

The context of this is developing a library for Topic Maps (which uses URI's
as the identifiers of the referenced topics) so I wanted to make sure that
any URI I found in a topic map was going to be parsed correctly.

The examples I posted are the normative tests from the RFC I mentioned; the
code itself is trivial...

Uri baseUri = new Uri("http://a/b/c/d;p?q");
for (int i = 0; i < tests.GetUpperBound(0); i++)
{
Uri relUri = new Uri(baseUri, tests[0]);
Assert.AreEqual(tests[1], loc.Scheme, "Mismatched scheme for " +
tests[0]);
Assert.AreEqual(tests[2], loc.Authority, "Mismatched authority for "
+ tests[0]);
Assert.AreEqual(tests[3], loc.PathString, "Mismatched path for " +
tests[0]);
Assert.AreEqual(tests[4], loc.Query, "Mismatched query for " +
tests[0]);
Assert.AreEqual(tests[5], loc.Fragment, "Mismatched fragment for " +
tests[0]);
}

I'll just have to develop my own Uri class for the time being.

Regards

Paul
 
Y

Yuan Ren[MSFT]

Hi Paul,

Thanks for your reply!

After my research, it seems Uri class still use RFC 2396 in .NET Framework
2.0 as below MSDN statement:
http://msdn2.microsoft.com/en-us/library/system.uriformatexception.aspx

For the current stage, I have sent the report to development team. Maybe in
the next version or service pack, the new RFC will be updated for Uri class.

Thanks for your issue!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top