SenseNet / sensenet

Open Source Content Services Platform written in .NET
https://sensenet.com
GNU General Public License v2.0
173 stars 112 forks source link

Bug, non-english characters in filename during uploads of checked-out content #644

Closed tomaswangen closed 5 years ago

tomaswangen commented 5 years ago

Hi,

I am unsure if this issue is in SenseNet.Client (2.0.0) or SenseNet (7.6.1).

It is slightly obscure as all these conditions must be present for it to occur:

Expected behavior: One new version Actual behavior: One file version per mutation (upload and/or field changes) + ClientException during checkin

A small example demonstrating the issue that should work on a baseline version:


using SenseNet.Client;
using System.IO;
using Xunit;

public class VersioningIssueTest {

    [Fact]
    public async void DemonstrateIssue() {

        ClientContext.Current.AddServer(new ServerContext() { Url = "http://localhost:8011/", Username = "admin", Password = "admin" });

        // Note: DocumentArchive test with versioning must be pre-created
        string folder = "/Root/Sites/Default_Site/test";

        await CreateDoc(folder, "a");
        await CreateDoc(folder, "b");
        await CreateDoc(folder, "1");
        await Assert.ThrowsAsync<ClientException>(() => CreateDoc(folder, "æ"));
        await Assert.ThrowsAsync<ClientException>(() => CreateDoc(folder, "ø"));
        await Assert.ThrowsAsync<ClientException>(() => CreateDoc(folder, "å"));
        await Assert.ThrowsAsync<ClientException>(() => CreateDoc(folder, "ä"));
        await Assert.ThrowsAsync<ClientException>(() => CreateDoc(folder, "Ä"));

    }

    private static async System.Threading.Tasks.Task CreateDoc(string folder, string name) {

        name += ".txt";
        var fullpath = folder + "/" + name;

        if (await Content.ExistsAsync(fullpath)) {
            var old = await Content.LoadAsync(fullpath);
            await old.DeleteAsync();
        }

        var content = Content.CreateNew(folder, "File", name);
        await content.SaveAsync();

        await content.CheckOutAsync();
        await Content.UploadAsync(folder, name, new MemoryStream(new byte[] { 36, 37, 38 }));
        await Content.UploadAsync(folder, name, new MemoryStream(new byte[] { 36, 36, 36 }));

        await content.CheckInAsync();
    }
}
tusmester commented 5 years ago

Hi @tomaswangen, thanks for the detailed report! 🛠

I could reproduce the issue. You're right, there should be only one new version, because when you upload a new binary to a file that is already locked for you, no new version should be created.

It seems that in this case when you upload to a locked file that has a special character in its name, it behaves differently: it creates a new version. We will look into this and keep track of the process on this issue.

tusmester commented 5 years ago

@tomaswangen we fixed the bug and released a new package. Please update the nuget package of the client library to version 2.0.1 and confirm that the issue has gone.

tomaswangen commented 5 years ago

@tusmester I can confirm that the fix works.

Thanks for resolving this very quickly!