Ensure TryGetMediaPath only returns true on non-empty values

This commit is contained in:
Ronald Barendse
2021-09-08 12:03:56 +02:00
parent 06cf4c29b1
commit b145f09368
3 changed files with 31 additions and 35 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Models;
@@ -6,32 +7,28 @@ namespace Umbraco.Cms.Core.PropertyEditors
{
public class MediaUrlGeneratorCollection : BuilderCollectionBase<IMediaUrlGenerator>
{
public MediaUrlGeneratorCollection(System.Func<IEnumerable<IMediaUrlGenerator>> items) : base(items)
{
}
public MediaUrlGeneratorCollection(Func<IEnumerable<IMediaUrlGenerator>> items)
: base(items)
{ }
public bool TryGetMediaPath(string propertyEditorAlias, object value, out string mediaPath)
{
// We can't get a media path from a null value
// The value will be null when uploading a brand new image, since we try to get the "old path" which doesn't exist yet.
if (value is null)
// The value will be null when uploading a brand new image, since we try to get the "old path" which doesn't exist yet
if (value is not null)
{
mediaPath = null;
return false;
}
foreach(IMediaUrlGenerator generator in this)
{
if (generator.TryGetMediaPath(propertyEditorAlias, value, out var mp))
foreach (IMediaUrlGenerator generator in this)
{
mediaPath = mp;
return true;
if (generator.TryGetMediaPath(propertyEditorAlias, value, out var generatorMediaPath))
{
mediaPath = generatorMediaPath;
return true;
}
}
}
mediaPath = null;
return false;
}
}
}