From a40bbbab51623f63a624661a4943ee8daafe120a Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Sun, 28 Sep 2014 15:16:43 -0400 Subject: [PATCH] #18826: Preventing shared references to repository collections --- src/Orchard/Data/Repository.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Orchard/Data/Repository.cs b/src/Orchard/Data/Repository.cs index 4f42f512a..eaf9b40de 100644 --- a/src/Orchard/Data/Repository.cs +++ b/src/Orchard/Data/Repository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; @@ -111,6 +112,27 @@ namespace Orchard.Data { Logger.Debug("Copy {0} {1}", source, target); var metadata = Session.SessionFactory.GetClassMetadata(typeof (T)); var values = metadata.GetPropertyValues(source, EntityMode.Poco); + + for (var index = 0; index < values.Length; index++) { + var value = values[index]; + if (value == null) + continue; + + var type = value.GetType(); + var isGenericList = type.GetInterfaces() + .Where(i => i.IsGenericType) + .Any(i => i.GetGenericTypeDefinition() == typeof(IList<>)); + + if(!isGenericList) + continue; + + var genericType = type.GetGenericArguments().First(); + var makeGenericType = typeof (List<>).MakeGenericType(new[] {genericType}); + + var listValues = ((IList)value); + values[index] = Activator.CreateInstance(makeGenericType, new[] { listValues }); + } + metadata.SetPropertyValues(target, values, EntityMode.Poco); }