diff --git a/src/Umbraco.Core/Models/Stylesheet.cs b/src/Umbraco.Core/Models/Stylesheet.cs
index 7381da0930..586c5915b2 100644
--- a/src/Umbraco.Core/Models/Stylesheet.cs
+++ b/src/Umbraco.Core/Models/Stylesheet.cs
@@ -33,11 +33,11 @@ namespace Umbraco.Core.Models
//re-parse it so we can check what properties are different and adjust the event handlers
var parsed = StylesheetHelper.ParseRules(Content).ToArray();
var names = parsed.Select(x => x.Name).ToArray();
- var existing = _properties.Value.Where(x => names.Contains(x.Name)).ToArray();
+ var existing = _properties.Value.Where(x => names.InvariantContains(x.Name)).ToArray();
//update existing
foreach (var stylesheetProperty in existing)
{
- var updateFrom = parsed.Single(x => x.Name == stylesheetProperty.Name);
+ var updateFrom = parsed.Single(x => x.Name.InvariantEquals(stylesheetProperty.Name));
//remove current event handler while we update, we'll reset it after
stylesheetProperty.PropertyChanged -= Property_PropertyChanged;
stylesheetProperty.Alias = updateFrom.Selector;
@@ -46,14 +46,14 @@ namespace Umbraco.Core.Models
stylesheetProperty.PropertyChanged += Property_PropertyChanged;
}
//remove no longer existing
- var nonExisting = _properties.Value.Where(x => names.Contains(x.Name) == false).ToArray();
+ var nonExisting = _properties.Value.Where(x => names.InvariantContains(x.Name) == false).ToArray();
foreach (var stylesheetProperty in nonExisting)
{
stylesheetProperty.PropertyChanged -= Property_PropertyChanged;
_properties.Value.Remove(stylesheetProperty);
}
//add new ones
- var newItems = parsed.Where(x => _properties.Value.Select(p => p.Name).Contains(x.Name) == false);
+ var newItems = parsed.Where(x => _properties.Value.Select(p => p.Name).InvariantContains(x.Name) == false);
foreach (var stylesheetRule in newItems)
{
var prop = new StylesheetProperty(stylesheetRule.Name, stylesheetRule.Selector, stylesheetRule.Styles);
@@ -128,7 +128,7 @@ namespace Umbraco.Core.Models
///
public void AddProperty(StylesheetProperty property)
{
- if (Properties.Any(x => x.Name == property.Name))
+ if (Properties.Any(x => x.Name.InvariantEquals(property.Name)))
{
throw new DuplicateNameException("The property with the name " + property.Name + " already exists in the collection");
}
@@ -151,7 +151,7 @@ namespace Umbraco.Core.Models
///
public void RemoveProperty(string name)
{
- if (Properties.Any(x => x.Name == name))
+ if (Properties.Any(x => x.Name.InvariantEquals(name)))
{
Content = StylesheetHelper.ReplaceRule(Content, name, null);
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs
index dcbab3dd88..87182e4ad0 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs
@@ -1,4 +1,5 @@
-using System.IO;
+using System.Data;
+using System.IO;
using System.Linq;
using System.Text;
using Moq;
@@ -118,6 +119,26 @@ p{font-size:2em;}"));
Assert.AreEqual(1, stylesheet.Properties.Count());
}
+ [Test]
+ public void Throws_When_Adding_Duplicate_Properties()
+ {
+ // Arrange
+ var provider = new FileUnitOfWorkProvider();
+ var unitOfWork = provider.GetUnitOfWork();
+
+ var repository = new StylesheetRepository(unitOfWork, _fileSystem);
+
+ // Act
+ var stylesheet = new Stylesheet("test-update.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" };
+ repository.AddOrUpdate(stylesheet);
+ unitOfWork.Commit();
+
+ stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-size:2em;"));
+
+ Assert.Throws(() => stylesheet.AddProperty(new StylesheetProperty("test", "p", "font-size:2em;")));
+
+ }
+
[Test]
public void Can_Perform_Delete()
{
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/stylesheet/property/EditStyleSheetProperty.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/stylesheet/property/EditStyleSheetProperty.aspx.cs
index 75471cd676..f058b31bb7 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/stylesheet/property/EditStyleSheetProperty.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/stylesheet/property/EditStyleSheetProperty.aspx.cs
@@ -45,7 +45,7 @@ namespace umbraco.cms.presentation.settings.stylesheet
var propName = IsPostBack ? OriginalName.Value : Request.QueryString["prop"];
- _stylesheetproperty = _sheet.Properties.FirstOrDefault(x => x.Name == propName);
+ _stylesheetproperty = _sheet.Properties.FirstOrDefault(x => x.Name.InvariantEquals(propName));
if (_stylesheetproperty == null) throw new InvalidOperationException("No stylesheet property found with name: " + Request.QueryString["prop"]);
Panel1.Text = ui.Text("stylesheet", "editstylesheetproperty", UmbracoUser);