DecaTec / Portable-WebDAV-Library

Moved to codeberg.org - https://codeberg.org/DecaTec/Portable-WebDAV-Library - The Portable WebDAV Library is a strongly typed, async WebDAV client library which is fully compliant to RFC 4918, RFC 4331 and "Additional WebDAV Collection Properties". It is implemented as .NETStandard 1.1 library in oder to be used on any platform supporting .NETStandard 1.1.
https://decatec.de
Microsoft Public License
46 stars 11 forks source link

WebDavSession.ListAsync delivered the containing folder if the requested folder path contained spaces #48

Closed domenico-barbieri closed 7 years ago

domenico-barbieri commented 7 years ago

If the requested folder path contains spaces, i.e. "Test folder", ListAsync returns the containing folder. Moreover, all the returned items have urls starting like that: "/remote.php/webdav/Test folder/remote.php/webdav/Test%folder/"

DecaTec commented 7 years ago

Can you provide a piece of code which produces this problem?

I've tried it with the following and couldn't reproduce the problem (on Nextcloud):

// Create WebDavSession
session.BaseUri = new Uri(@"http://mycloud.com/remote.php/webdav");
var items = await session.ListAsync("Test Folder");
domenico-barbieri commented 7 years ago

I'm using the portable library in a Xamarin.Android project, logging to a Nextcloud server. Here it is some sample code:

        var session = new WebDavSession(host, new System.Net.NetworkCredential(username, password));
        session.BaseUri = new Uri(host + "/remote.php/webdav");

        var items = await session.ListAsync("Test folder");
        foreach(var item in items)
        {
            Debug.Write(item.Uri);
        }

Running this test code in the OnCreate method of an Activity produce a list with the following item (the folder is empty): .../remote.php/webdav/Test folder/remote.php/webdav/Test%2520folder/

DecaTec commented 7 years ago

There is a problem with the class Uri on Xamarin. In order to cancat URIs, please use the class UriHelper contained in the library. For more information about the PWL on Xamaran, please take a look at the wiki: https://github.com/DecaTec/Portable-WebDAV-Library/wiki/Xamarin

domenico-barbieri commented 7 years ago

Yes, I also got the conclusion that the Uri class behaves differently between iOS/Android. The use of UriHelper does not solve the issue. If I run the following code, the result is the same:

        var session = new WebDavSession(host, new System.Net.NetworkCredential(username, password));
        session.BaseUri = UriHelper.CreateUriFromUrl(UriHelper.CombineUrl(host, "/remote.php/webdav"));

        var uri = UriHelper.CombineUriAndUrl(session.BaseUri, "Test folder");
        var items = await session.ListAsync(uri);
        foreach(var item in items)
        {
            Debug.Write(item.Uri);
        }
DecaTec commented 7 years ago

OK, was able to reproduce the problem: When having URLs with spaces and 'file' scheme (which seems to be a problem on Xamarin), Uri.AbsolutePath messes up. So from test/test%20folder, you'll receive test/test%2520folder. This messes up all subsequent Uri/URL handling.

I was able to fix this with https://github.com/DecaTec/Portable-WebDAV-Library/commit/d8012cb86e783143c0144e6c4a00398388999988 by using the property Uri.LocalPath instead.

I hope that this doesn't break anything on the iOS side...

I'll prepare an update for the library.

DecaTec commented 7 years ago

Released v1.0.1.0 - will be available on NuGet in a few minutes.

domenico-barbieri commented 7 years ago

It looks working propely on Android, I'll test on iOS ASAP, thank you

domenico-barbieri commented 7 years ago

It works correctly on iOS too.

DecaTec commented 7 years ago

Great! Thanks for the feedback.