Wednesday, August 27, 2008

Uri quirks..

Got bitten by this as this i was using the Uri class to combine some parent child resources. Msdn states that Uri(uri, string) combines the base and relative uri's w/o giving details of what that means. The following examples show that combining two uri's is not obvious :).
(http://www.xyz.com/p1/p2, c1) => http://www.xyz.com/p1/c1
(http://www.xyz.com/p1/p2/, c1) => http://www.xyz.com/p1/p2/c1
(http://www.xyz.com/p1/p2, /c1) => http://www.xyz.com/c1
(http://www.xyz.com/p1/p2/, /c1) => http://www.xyz.com/c1
(http://www.xyz.com/p1/p2, ./c1) => http://www.xyz.com/p1/c1
(http://www.xyz.com/p1/p2/, ./c1) => http://www.xyz.com/p1/p2/c1

 
The gory details of the combination algorithm can be found at http://www.apps.ietf.org/rfc/rfc3986.html#sec-5.2.