[Mono-dev] Possible issue with Uri.cs
Miguel de Icaza
miguel at xamarin.com
Thu May 15 04:01:38 UTC 2014
Hello,
This is an unfortunate problem with the design of the Uri class. They
designed it so that it automatically turned things that looked like
filenames into a file uri, instead of mandating that the "file:" scheme be
present.
I have struggled to figure out a solution to the problem.
This means that when you do:
new Uri ("c:/foo");
It returns a Uri like this: "file://c:/foo" (or something like that, I do
not have windows here).
To support this, we made new Uri ("/foo") become: file:///foo
This causes problems in countless places, in particular in places that
distinguish between absolute Uris and relative uris.
There are a bunch of bugs filed around this particular issue, and fixing
will just introduce a different set of bugs.
Miguel
On Wed, May 14, 2014 at 10:56 AM, SilentBob <cinnamondonkey at gmail.com>wrote:
> Hi,
>
> I am seeing an issue with XmlDocument .Load() always throwing an
> exception.
> I have studied the code in the class library and noticed the following
> issue
> that can be narrowed down to Uri.cs.
>
> Path.GetFullPath("dev0:/dir1/dir2") => "//dev0:/dir1/dir2"
> Uri(Path.GetFullPath("dev0:/dir1/dir2")) => "file:///dev0:/dir1/dir2"
>
> Note '///' in XmlDocument seems to cause a problem with FileStream which
> throws and exception along the lines of can not find path
> "/dev0:/dir1/dir2".
>
> FileStream only seems happy seeing the following format: "dev0:/dir1/dir2"
>
> Looking at Uri.cs I can see:
>
> private void ParseAsUnixAbsoluteFilePath (string uriString)
> {
> isUnixFilePath = true;
> scheme = UriSchemeFile;
> port = -1;
> fragment = String.Empty;
> query = String.Empty;
> host = String.Empty;
> path = null;
>
> if (uriString.Length >= 2 && uriString [0] == '/'
> && uriString [1] ==
> '/') {
> uriString = uriString.TrimStart (new char
> [] {'/'});
> // Now we don't regard //foo/bar as "foo"
> host.
> /*
> int pos = uriString.IndexOf ('/');
> if (pos > 0) {
> path = '/' + uriString.Substring
> (pos + 1);
> host = uriString.Substring (0,
> pos);
> } else { // "///server"
> host = uriString;
> path = String.Empty;
> }
> */
> path = '/' + uriString;
> }
> if (path == null)
> path = uriString;
> }
>
>
> Why is the code doing:
>
> path = '/' + uriString;
>
> After stripping the leading '//' ?
>
> I'm assuming at some point the library simply tags on or removes "file://"
> as required.
>
> Regards,
> Shaun
>
>
>
> --
> View this message in context:
> http://mono.1490590.n4.nabble.com/Possible-issue-with-Uri-cs-tp4662793.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140515/76f1ad80/attachment.html>
More information about the Mono-devel-list
mailing list