From 62532ef26d6eacf9b1c226311d7763552f9c2a76 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 7 Jul 2011 12:35:31 -0700 Subject: [PATCH] Fix Herald to accept new JSON encoding of sparse arrays Summary: JX.JSON was recently changed to use JSON.stringify (the native implementation) if it is available. The native implementation has a behavioral difference from the Javelin implementation, in that it does not compact sparse arrays. Ignore nulls resulting from removals when processing the encoded action and condition lists. Test Plan: Removed conditions from Herald rules. Reviewed By: aran Reviewers: aran, cpojer, jungejason CC: aran, epriestley Differential Revision: 606 --- .../herald/controller/rule/HeraldRuleController.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/applications/herald/controller/rule/HeraldRuleController.php b/src/applications/herald/controller/rule/HeraldRuleController.php index 7c9d9d5f5c..b2d0a73440 100644 --- a/src/applications/herald/controller/rule/HeraldRuleController.php +++ b/src/applications/herald/controller/rule/HeraldRuleController.php @@ -93,6 +93,12 @@ class HeraldRuleController extends HeraldController { $conditions = array(); foreach ($data['conditions'] as $condition) { + if ($condition === null) { + // We manage this as a sparse array on the client, so may receive + // NULL if conditions have been removed. + continue; + } + $obj = new HeraldCondition(); $obj->setFieldName($condition[0]); $obj->setFieldCondition($condition[1]); @@ -149,6 +155,11 @@ class HeraldRuleController extends HeraldController { $actions = array(); foreach ($data['actions'] as $action) { + if ($action === null) { + // Sparse on the client; removals can give us NULLs. + continue; + } + $obj = new HeraldAction(); $obj->setAction($action[0]);