From d4994e99cef0eae745b251edeb68556c280fd47d Mon Sep 17 00:00:00 2001 From: Tim Conkling Date: Tue, 7 Nov 2017 16:52:40 -0800 Subject: [PATCH] Validate getProductsInfo() The iOS ANE will crash on invalid getProductsInfo() input (like passing numbers instead of Strings). Dispatch an error event, instead of blowing up, on bad input --- .../ane/AirInAppPurchase/InAppPurchase.as | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/actionscript/src/com/freshplanet/ane/AirInAppPurchase/InAppPurchase.as b/actionscript/src/com/freshplanet/ane/AirInAppPurchase/InAppPurchase.as index ae68b43..5654680 100644 --- a/actionscript/src/com/freshplanet/ane/AirInAppPurchase/InAppPurchase.as +++ b/actionscript/src/com/freshplanet/ane/AirInAppPurchase/InAppPurchase.as @@ -138,7 +138,11 @@ package com.freshplanet.ane.AirInAppPurchase { productsIds ||= []; subscriptionIds ||= []; - _context.call("getProductsInfo", productsIds, subscriptionIds); + if (!_allStrings(productsIds) || !_allStrings(subscriptionIds)) { + _dispatchEvent(InAppPurchaseEvent.PRODUCT_INFO_ERROR, "Product and subscription IDs must all be strings"); + } else { + _context.call("getProductsInfo", productsIds, subscriptionIds); + } } } @@ -214,6 +218,17 @@ package com.freshplanet.ane.AirInAppPurchase { _dispatchEvent(event.code, event.level); } + /** Return true if all values in the array are strings */ + private static function _allStrings(arr:Array):Boolean { + + for each (var obj:Object in arr) { + if (!(obj is String)) { + return false; + } + } + return true; + } + /** * * @param strings