Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Packages/Audience/Runtime/AudienceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ public class AudienceConfig

// Test seam for HttpTransport; not part of the public API.
internal System.Net.Http.HttpMessageHandler? HttpHandler { get; set; }

// Makes a shallow copy so Init can fill in PersistentDataPath without
// modifying the caller's object. Delegates and handlers (OnError,
// HttpHandler) are deliberately kept as the same instance — cloning
// them would break their behaviour.
internal AudienceConfig Clone() => (AudienceConfig)MemberwiseClone();
}
}
7 changes: 6 additions & 1 deletion src/Packages/Audience/Runtime/ImmutableAudience.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ public static class ImmutableAudience
public static void Init(AudienceConfig config)
{
if (config == null) throw new ArgumentNullException(nameof(config));

// Copy the caller's config so filling in PersistentDataPath below
// doesn't change the object they passed in. Validating after the
// clone keeps the compiler's null-flow analysis for PublishableKey
// alive through the HttpTransport constructor below.
config = config.Clone();
if (string.IsNullOrEmpty(config.PublishableKey))
throw new ArgumentException("PublishableKey is required", nameof(config));

if (string.IsNullOrEmpty(config.PersistentDataPath))
config.PersistentDataPath = DefaultPersistentDataPathProvider?.Invoke();
if (string.IsNullOrEmpty(config.PersistentDataPath))
Expand Down
Loading