diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs new file mode 100644 index 0000000000..cf034c8c29 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs @@ -0,0 +1,28 @@ +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + /// + /// We need this property converter so that we always force the value of a label to be a string + /// + /// + /// Without a property converter defined for the label type, the value will be converted with + /// the `ConvertUsingDarkMagic` method which will try to parse the value into it's correct type, but this + /// can cause issues if the string is detected as a number and then strips leading zeros. + /// Example: http://issues.umbraco.org/issue/U4-7929 + /// + [DefaultPropertyValueConverter] + [PropertyValueType(typeof (string))] + [PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] + public class LabelValueConverter : PropertyValueConverterBase + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return Constants.PropertyEditors.NoEditAlias.Equals(propertyType.PropertyEditorAlias); + } + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + return source == null ? string.Empty : source.ToString(); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 92afe4105c..998e166e27 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -478,6 +478,7 @@ +