Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ build.gradle_mine
*.csproj

*.cache

# Local SDK source checkouts for cross-referencing (not part of the plugin)
.sdk_workspace/
36 changes: 28 additions & 8 deletions Assets/AppsFlyer/AFMiniJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;

Expand Down Expand Up @@ -90,6 +91,7 @@ public static object Deserialize(string json) {

sealed class Parser : IDisposable {
const string WORD_BREAK = "{}[],:\"";
static readonly char[] FractionOrExponentChars = { '.', 'e', 'E' };

public static bool IsWordBreak(char c) {
return Char.IsWhiteSpace(c) || WORD_BREAK.IndexOf(c) != -1;
Expand Down Expand Up @@ -290,14 +292,17 @@ string ParseString() {
object ParseNumber() {
string number = NextWord;

if (number.IndexOf('.') == -1) {
// JSON numbers are culture-invariant. Parsing with the current culture breaks on
// comma-decimal locales (vi-VN/de-DE treat '.' as a thousands separator, so "0.5" -> 5).
if (number.IndexOfAny(FractionOrExponentChars) == -1) {
long parsedInt;
Int64.TryParse(number, out parsedInt);
return parsedInt;
if (Int64.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedInt)) {
return parsedInt;
}
}

double parsedDouble;
Double.TryParse(number, out parsedDouble);
Double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedDouble);
return parsedDouble;
}

Expand Down Expand Up @@ -524,8 +529,18 @@ void SerializeOther(object value) {
// NOTE: decimals lose precision during serialization.
// They always have, I'm just letting you know.
// Previously floats and doubles lost precision too.
// JSON numbers must be culture-invariant: the current culture would emit "0,0123" on
// comma-decimal locales, producing invalid JSON that the native RPC bridge rejects.
// NaN/Infinity have no JSON representation; they're emitted as 0 (not null) so both native
// RPC layers treat them the same — Android's parser maps null to 0 for numeric params while
// iOS rejects null, so null would drop the event on iOS but log 0 on Android.
if (value is float) {
builder.Append(((float) value).ToString("R"));
float f = (float) value;
if (float.IsNaN(f) || float.IsInfinity(f)) {
builder.Append('0');
} else {
builder.Append(f.ToString("R", CultureInfo.InvariantCulture));
}
} else if (value is int
|| value is uint
|| value is long
Expand All @@ -534,12 +549,17 @@ void SerializeOther(object value) {
|| value is short
|| value is ushort
|| value is ulong) {
builder.Append(value);
builder.Append(Convert.ToString(value, CultureInfo.InvariantCulture));
} else if (value is double
|| value is decimal) {
builder.Append(Convert.ToDouble(value).ToString("R"));
double d = Convert.ToDouble(value, CultureInfo.InvariantCulture);
if (double.IsNaN(d) || double.IsInfinity(d)) {
builder.Append('0');
} else {
builder.Append(d.ToString("R", CultureInfo.InvariantCulture));
}
} else {
SerializeString(value.ToString());
SerializeString(Convert.ToString(value, CultureInfo.InvariantCulture));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/AppsFlyer/AppsFlyer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace AppsFlyerSDK
#pragma warning disable CS1998
public class AppsFlyer : MonoBehaviour
{
public static readonly string kAppsFlyerPluginVersion = "7.0.4";
public static readonly string kAppsFlyerPluginVersion = "7.0.41";
public static string CallBackObjectName = null;
private static EventHandler onSessionReady;
private static Action<string> onConversionDataSuccessCallback;
Expand Down
2 changes: 1 addition & 1 deletion Assets/AppsFlyer/AppsFlyerEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private string getDeepLinkParameter(string name)
{
if (deepLink != null && deepLink.ContainsKey(name) && deepLink[name] != null)
{
return deepLink[name].ToString();
return Convert.ToString(deepLink[name], System.Globalization.CultureInfo.InvariantCulture);
}

return null;
Expand Down
262 changes: 262 additions & 0 deletions Assets/AppsFlyer/Tests/Tests_Suite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,4 +1107,266 @@ public async Task RegisterDeepLinkListener_iOS_SendsRegisterDeeplinkListener()
}
#endif
}

/// <summary>
/// DELIVERY-135217: AFMiniJSON used the current culture for numbers, so on comma-decimal
/// locales (vi-VN, de-DE, ...) requests carried "revenue":0,0123 (invalid JSON, dropped by the
/// native RPC bridge) and parsed native payloads silently corrupted fractional values.
/// Every test runs under each comma-decimal culture below.
/// </summary>
[TestFixture("vi-VN")]
[TestFixture("de-DE")]
[TestFixture("fr-FR")]
[TestFixture("ru-RU")]
public class AFMiniJSONCultureTests
{
private readonly string _cultureName;
private System.Globalization.CultureInfo _savedCulture;
private IAppsFlyerRPCClient mockRpc;
private readonly List<GameObject> _spawned = new List<GameObject>();

public AFMiniJSONCultureTests(string cultureName)
{
_cultureName = cultureName;
}

[SetUp]
public void SetUp()
{
_savedCulture = System.Globalization.CultureInfo.CurrentCulture;
System.Globalization.CultureInfo culture;
try
{
culture = new System.Globalization.CultureInfo(_cultureName);
}
catch (System.Globalization.CultureNotFoundException)
{
Assert.Inconclusive(_cultureName + " culture data is not available on this runtime");
return;
}
if (culture.NumberFormat.NumberDecimalSeparator != ",")
Assert.Inconclusive(_cultureName + " is not a comma-decimal culture on this runtime");
System.Globalization.CultureInfo.CurrentCulture = culture;

mockRpc = Substitute.For<IAppsFlyerRPCClient>();
AppsFlyerRPCClient.instance = mockRpc;
}

[TearDown]
public void TearDown()
{
System.Globalization.CultureInfo.CurrentCulture = _savedCulture;
AppsFlyerRPCClient.instance = AppsFlyerRPCClient.DefaultInstance;
AppsFlyer.CallBackObjectName = null;
typeof(AppsFlyer).GetField("onConversionDataSuccessCallback", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
?.SetValue(null, null);
typeof(AppsFlyer).GetField("onConversionDataFailCallback", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
?.SetValue(null, null);
typeof(AppsFlyer).GetField("onDeepLinkListenerCallback", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
?.SetValue(null, null);
foreach (var go in _spawned) UnityEngine.Object.DestroyImmediate(go);
_spawned.Clear();
}

// ── Serialize ──────────────────────────────────────────────────────────────

[Test]
public void Serialize_Double_UsesDotDecimalSeparator()
{
Assert.AreEqual("{\"v\":0.0123}", Json.Serialize(new Dictionary<string, object> { { "v", 0.0123 } }));
}

[Test]
public void Serialize_Float_UsesDotDecimalSeparator()
{
Assert.AreEqual("{\"v\":1.5}", Json.Serialize(new Dictionary<string, object> { { "v", 1.5f } }));
}

[Test]
public void Serialize_Decimal_UsesDotDecimalSeparator()
{
Assert.AreEqual("{\"v\":19.99}", Json.Serialize(new Dictionary<string, object> { { "v", 19.99m } }));
}

[Test]
public void Serialize_NegativeAndLargeIntegers_AreInvariant()
{
// Some cultures use U+2212 (minus sign) instead of '-'; force it so the test actually
// fails if integers are formatted with the current culture.
var withUnicodeMinus = (System.Globalization.CultureInfo)System.Globalization.CultureInfo.CurrentCulture.Clone();
withUnicodeMinus.NumberFormat.NegativeSign = "\u2212";
System.Globalization.CultureInfo.CurrentCulture = withUnicodeMinus;

Assert.AreEqual("[-42,1234567,-9000000000]", Json.Serialize(new List<object> { -42, 1234567, -9000000000L }));
}

[Test]
public void Serialize_NonPrimitiveFallback_IsInvariant()
{
var value = new DateTime(2026, 11, 4, 13, 5, 0);
Assert.AreEqual("{\"v\":\"" + value.ToString(System.Globalization.CultureInfo.InvariantCulture) + "\"}",
Json.Serialize(new Dictionary<string, object> { { "v", value } }));
}

[Test]
public void Serialize_NaNAndInfinity_BecomeZero()
{
Assert.AreEqual("[0,0,0,0]",
Json.Serialize(new List<object> { double.NaN, double.PositiveInfinity, float.NaN, float.NegativeInfinity }));
}

// ── Deserialize ────────────────────────────────────────────────────────────

[Test]
public void Deserialize_Fraction_IsNotTreatedAsThousandsSeparator()
{
var dict = Json.Deserialize("{\"v\":0.5,\"w\":1234.25}") as Dictionary<string, object>;
Assert.AreEqual(0.5, (double)dict["v"]);
Assert.AreEqual(1234.25, (double)dict["w"]);
}

[Test]
public void Deserialize_Exponent_IsParsedAsDouble()
{
var list = Json.Deserialize("[1E-05,-2.5e3,3e+2]") as List<object>;
Assert.AreEqual(1e-05, (double)list[0], 1e-12);
Assert.AreEqual(-2500.0, (double)list[1]);
Assert.AreEqual(300.0, (double)list[2]);
}

[Test]
public void Deserialize_Integers_StayLong()
{
var list = Json.Deserialize("[-42,0,9000000000]") as List<object>;
Assert.AreEqual(-42L, list[0]);
Assert.AreEqual(0L, list[1]);
Assert.AreEqual(9000000000L, list[2]);
}

[Test]
public void Deserialize_IntegerBeyondLongRange_FallsBackToDouble()
{
var list = Json.Deserialize("[99999999999999999999]") as List<object>;
Assert.IsInstanceOf<double>(list[0]);
Assert.AreEqual(1e20, (double)list[0], 1e5);
}

[Test]
public void RoundTrip_PreservesFractionalValues()
{
var original = new Dictionary<string, object> { { "a", 0.0123 }, { "b", -7.25 }, { "c", 1e-7 } };
var parsed = Json.Deserialize(Json.Serialize(original)) as Dictionary<string, object>;
Assert.AreEqual(0.0123, (double)parsed["a"]);
Assert.AreEqual(-7.25, (double)parsed["b"]);
Assert.AreEqual(1e-7, (double)parsed["c"], 1e-15);
}

// ── Public APIs whose RPC request carries numbers ──────────────────────────

[Test]
[Timeout(10000)]
public async Task LogAdRevenue_RequestIsValidJsonWithDotDecimal()
{
Dictionary<string, object> captured = null;
mockRpc.When(x => x.ExecuteFire("logAdRevenue", Arg.Any<Dictionary<string, object>>()))
.Do(ci => captured = ci.ArgAt<Dictionary<string, object>>(1));

await AppsFlyer.logAdRevenue(new AFAdRevenueData("ironSource", MediationNetwork.IronSource, "USD", 0.0123), null);

string json = AppsFlyerRPCClient.DefaultInstance.BuildRequest("logAdRevenue", captured);
StringAssert.Contains("\"revenue\":0.0123", json);
var request = Json.Deserialize(json) as Dictionary<string, object>;
Assert.IsNotNull(request, "request JSON must parse: " + json);
Assert.AreEqual(0.0123, (double)((Dictionary<string, object>)request["params"])["revenue"]);
}

[TestCase(double.NaN)]
[TestCase(double.PositiveInfinity)]
[TestCase(double.NegativeInfinity)]
[Timeout(10000)]
public async Task LogAdRevenue_NonFiniteRevenue_IsSentAsZero(double revenue)
{
Dictionary<string, object> captured = null;
mockRpc.When(x => x.ExecuteFire("logAdRevenue", Arg.Any<Dictionary<string, object>>()))
.Do(ci => captured = ci.ArgAt<Dictionary<string, object>>(1));

await AppsFlyer.logAdRevenue(new AFAdRevenueData("ironSource", MediationNetwork.IronSource, "USD", revenue), null);

string json = AppsFlyerRPCClient.DefaultInstance.BuildRequest("logAdRevenue", captured);
StringAssert.Contains("\"revenue\":0,", json);
Assert.IsNotNull(Json.Deserialize(json), "request JSON must parse: " + json);
}

[Test]
[Timeout(10000)]
public async Task LogLocation_NonFiniteCoordinates_AreSentAsZero()
{
Dictionary<string, object> captured = null;
mockRpc.When(x => x.ExecuteFire("logLocation", Arg.Any<Dictionary<string, object>>()))
.Do(ci => captured = ci.ArgAt<Dictionary<string, object>>(1));

await AppsFlyer.logLocation(double.NaN, double.PositiveInfinity);

string json = AppsFlyerRPCClient.DefaultInstance.BuildRequest("logLocation", captured);
StringAssert.Contains("\"latitude\":0", json);
StringAssert.Contains("\"longitude\":0", json);
Assert.IsNotNull(Json.Deserialize(json), "request JSON must parse: " + json);
}

[Test]
[Timeout(10000)]
public async Task LogLocation_RequestIsValidJsonWithDotDecimal()
{
Dictionary<string, object> captured = null;
mockRpc.When(x => x.ExecuteFire("logLocation", Arg.Any<Dictionary<string, object>>()))
.Do(ci => captured = ci.ArgAt<Dictionary<string, object>>(1));

await AppsFlyer.logLocation(10.7769, -106.7009);

string json = AppsFlyerRPCClient.DefaultInstance.BuildRequest("logLocation", captured);
StringAssert.Contains("\"latitude\":10.7769", json);
StringAssert.Contains("\"longitude\":-106.7009", json);
Assert.IsNotNull(Json.Deserialize(json), "request JSON must parse: " + json);
}

#if UNITY_IOS || UNITY_STANDALONE_OSX
[Test]
[Timeout(10000)]
public async Task HandlePushNotifications_NumericPayloadValues_AreInvariant()
{
Dictionary<string, object> captured = null;
mockRpc.When(x => x.ExecuteFire("handlePushNotification", Arg.Any<Dictionary<string, object>>()))
.Do(ci => captured = ci.ArgAt<Dictionary<string, object>>(1));

await AppsFlyer.handlePushNotifications(new Dictionary<string, object> { { "score", 2.5 } });

string json = AppsFlyerRPCClient.DefaultInstance.BuildRequest("handlePushNotification", captured);
StringAssert.Contains("\"score\":2.5", json);
}
#endif

// ── Callbacks parsed from native payloads ──────────────────────────────────

[Test]
[Timeout(10000)]
public async Task ConversionData_RoundTripThroughOnRPCEvent_PreservesFractions()
{
string success = null;
await AppsFlyer.registerConversionListener(d => success = d, e => { });
var go = new GameObject();
_spawned.Add(go);
go.AddComponent<AppsFlyer>().onRPCEvent("{\"event\":\"onConversionDataSuccess\",\"data\":{\"cost\":0.5}}");

Assert.IsNotNull(success);
var data = AppsFlyer.CallbackStringToDictionary(success);
Assert.AreEqual(0.5, (double)data["cost"]);
}

[Test]
public void DeepLinkEventsArgs_NumericValue_FormatsInvariant()
{
var args = new DeepLinkEventsArgs("{\"status\":\"FOUND\",\"deepLink\":{\"deep_link_value\":0.5}}");
Assert.AreEqual("0.5", args.getDeepLinkValue());
}
}
}
2 changes: 1 addition & 1 deletion Assets/AppsFlyer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "appsflyer-unity-plugin",
"displayName": "AppsFlyer",
"description": "AppsFlyer Unity plugin",
"version": "7.0.4",
"version": "7.0.41",
"unity": "2023.1",
"license": "MIT"
}
Loading
Loading