Skip to content

Commit 50f6024

Browse files
authored
Merge commit from fork
1 parent a8080d0 commit 50f6024

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public static class ContentSettingsExtensions
1414
/// <c>true</c> if the file extension is allowed for upload; otherwise, <c>false</c>.
1515
/// </returns>
1616
public static bool IsFileAllowedForUpload(this ContentSettings contentSettings, string extension)
17-
=> contentSettings.AllowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension)) ||
18-
(contentSettings.AllowedUploadedFileExtensions.Any() == false && contentSettings.DisallowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension)) == false);
17+
=> contentSettings.AllowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension.Trim())) ||
18+
(contentSettings.AllowedUploadedFileExtensions.Any() == false && contentSettings.DisallowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension.Trim())) == false);
1919

2020
/// <summary>
2121
/// Gets the auto-fill configuration for a specified property alias.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) Umbraco.
2+
// See LICENSE for more details.
3+
4+
using NUnit.Framework;
5+
using Umbraco.Cms.Core.Configuration.Models;
6+
using Umbraco.Extensions;
7+
8+
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration;
9+
10+
[TestFixture]
11+
public class ContentSettingsExtensionsTests
12+
{
13+
[TestCase("jpg")]
14+
[TestCase("JPG")]
15+
[TestCase("jpg ")]
16+
public void IsFileAllowedForUpload_Allows_File_In_Allow_List(string extension)
17+
{
18+
var contentSettings = new ContentSettings
19+
{
20+
AllowedUploadedFileExtensions = new[] { "jpg", "png" }.ToHashSet(),
21+
};
22+
23+
Assert.IsTrue(contentSettings.IsFileAllowedForUpload(extension));
24+
}
25+
26+
[TestCase("gif")]
27+
[TestCase("GIF")]
28+
[TestCase("gif ")]
29+
public void IsFileAllowedForUpload_Rejects_File_Not_In_Allow_List(string extension)
30+
{
31+
var contentSettings = new ContentSettings
32+
{
33+
AllowedUploadedFileExtensions = new[] { "jpg", "png" }.ToHashSet(),
34+
};
35+
36+
Assert.IsFalse(contentSettings.IsFileAllowedForUpload(extension));
37+
}
38+
39+
[TestCase("jpg")]
40+
[TestCase("JPG")]
41+
[TestCase("jpg ")]
42+
public void IsFileAllowedForUpload_Allows_File_Not_In_Disallow_List(string extension)
43+
{
44+
var contentSettings = new ContentSettings
45+
{
46+
DisallowedUploadedFileExtensions = new[] { "gif", "png" }.ToHashSet(),
47+
};
48+
49+
Assert.IsTrue(contentSettings.IsFileAllowedForUpload(extension));
50+
}
51+
52+
[TestCase("gif")]
53+
[TestCase("GIF")]
54+
[TestCase("gif ")]
55+
public void IsFileAllowedForUpload_Rejects_File_In_Disallow_List(string extension)
56+
{
57+
var contentSettings = new ContentSettings
58+
{
59+
DisallowedUploadedFileExtensions = new[] { "gif", "png" }.ToHashSet(),
60+
};
61+
62+
Assert.IsFalse(contentSettings.IsFileAllowedForUpload(extension));
63+
}
64+
65+
[Test]
66+
public void IsFileAllowedForUpload_Allows_File_In_Allow_List_Even_If_Also_In_Disallow_List()
67+
{
68+
var contentSettings = new ContentSettings
69+
{
70+
AllowedUploadedFileExtensions = new[] { "jpg", "png" }.ToHashSet(),
71+
DisallowedUploadedFileExtensions = new[] { "jpg", }.ToHashSet(),
72+
};
73+
74+
Assert.IsTrue(contentSettings.IsFileAllowedForUpload("jpg"));
75+
}
76+
}

0 commit comments

Comments
 (0)