From e7587ae27b183369679a194d51f1bcd7aebb7d7c Mon Sep 17 00:00:00 2001 From: James Simone <16430727+jamessimone@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:17:46 -0400 Subject: [PATCH] Fixes #623 by properly parsing nested IN conditions during recursive where clause operations --- extra-tests/classes/RollupEvaluatorTests.cls | 9 +++++++++ rollup/core/classes/RollupEvaluator.cls | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/extra-tests/classes/RollupEvaluatorTests.cls b/extra-tests/classes/RollupEvaluatorTests.cls index 21471857..18516c0c 100644 --- a/extra-tests/classes/RollupEvaluatorTests.cls +++ b/extra-tests/classes/RollupEvaluatorTests.cls @@ -1258,6 +1258,15 @@ private class RollupEvaluatorTests { System.assertEquals(false, eval.matches(nonMatch3)); } + @IsTest + static void stripsExtraParantheticalStructures() { + String whereClause = '(Name IN (\'0-Current\', \'1-30 Days\', \'31-60 Days\')) AND Name IN (\'0-Current\', \'1-30 Days\', \'31-60 Days\')'; + + RollupEvaluator eval = new RollupEvaluator.WhereFieldEvaluator(whereClause, ContactPointConsent.SObjectType); + + System.assertEquals(true, eval.matches(new ContactPointConsent(Name = '0-Current'))); + } + private static String getSoqlCompliantDatetime(Datetime dt) { return dt.format('yyyy-MM-dd\'T\'HH:mm:ssZ'); } diff --git a/rollup/core/classes/RollupEvaluator.cls b/rollup/core/classes/RollupEvaluator.cls index a0ea0e21..4c915cf4 100644 --- a/rollup/core/classes/RollupEvaluator.cls +++ b/rollup/core/classes/RollupEvaluator.cls @@ -393,7 +393,14 @@ public without sharing abstract class RollupEvaluator implements Rollup.Evaluato String value = words[++index]; if (criteria.endsWithIgnoreCase('in')) { while (value.endsWith(')') == false) { - value += ' ' + words[++index]; + String nextWord = words[++index]; + value += ' ' + nextWord.removeEnd(')'); + if (index + 1 == words.size()) { + break; + } + } + if (value.startsWith('(') && value.endsWith(')') == false) { + value += ')'; } } else if (value.startsWith('\'') && value.endsWith('\'') == false) { String tempVal = value;