Skip to content

Commit ac288a1

Browse files
fix(audience): truncate string values inside properties/traits dicts
Top-level fields (eventName, anonymousId, userId, identityType, fromId/fromType/toId/toType) were being truncated to Constants.MaxFieldLength, but string values inside the caller-supplied properties dict and traits dict were not. This left typed-event fields (Progression.World, Purchase.ItemName, MilestoneReached.Name, etc.) and custom-event property values un-truncated - so a caller passing a 10MB string through an IEvent impl or Track(string, Dictionary) would ship the full string to the backend. Adds MessageBuilder.TruncateStringValues, called on properties inside Track() and on traits inside Identify() just before assigning to the outgoing msg. Mutates the dict in place (caller owns fresh or snapshotted dicts at this point - no shared-state hazard). Non-string values are left untouched. Alias doesn't carry a properties/traits dict so no change there.
1 parent 120f890 commit ac288a1

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/Packages/Audience/Runtime/Events/MessageBuilder.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ internal static Dictionary<string, object> Track(
2424
msg[MessageFields.UserId] = Truncate(userId, Constants.MaxFieldLength);
2525

2626
if (properties != null && properties.Count > 0)
27+
{
28+
TruncateStringValues(properties);
2729
msg["properties"] = properties;
30+
}
2831

2932
return msg;
3033
}
@@ -48,7 +51,10 @@ internal static Dictionary<string, object> Identify(
4851
msg["identityType"] = Truncate(identityType, Constants.MaxFieldLength);
4952

5053
if (traits != null && traits.Count > 0)
54+
{
55+
TruncateStringValues(traits);
5156
msg["traits"] = traits;
57+
}
5258

5359
return msg;
5460
}
@@ -90,5 +96,16 @@ private static string Truncate(string s, int maxLen)
9096
return s;
9197
return s.Substring(0, maxLen);
9298
}
99+
100+
private static void TruncateStringValues(Dictionary<string, object> dict)
101+
{
102+
// Snapshot keys to avoid mutating the collection during iteration.
103+
var keys = new List<string>(dict.Keys);
104+
foreach (var key in keys)
105+
{
106+
if (dict[key] is string s && s.Length > Constants.MaxFieldLength)
107+
dict[key] = Truncate(s, Constants.MaxFieldLength);
108+
}
109+
}
93110
}
94111
}

0 commit comments

Comments
 (0)