From 27fd83160d008e93fcf54be3d1804696710594b7 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Fri, 17 Nov 2023 15:59:26 -0500 Subject: [PATCH] strip leading/trailing whitespaces --- .../java/io/cryostat/agent/triggers/SmartTrigger.java | 10 +++++----- .../java/io/cryostat/agent/triggers/TriggerParser.java | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/cryostat/agent/triggers/SmartTrigger.java b/src/main/java/io/cryostat/agent/triggers/SmartTrigger.java index 5f2cef27..b8c544a3 100644 --- a/src/main/java/io/cryostat/agent/triggers/SmartTrigger.java +++ b/src/main/java/io/cryostat/agent/triggers/SmartTrigger.java @@ -24,8 +24,8 @@ public class SmartTrigger { private static final String DURATION_PATTERN_STR = - "(TargetDuration[<>=]+duration\\(['\"](\\d+[sSmMhH]+)['\"]\\))"; - private static final String DEFINITION_PATTERN_STR = "(.+)(?:;)" + DURATION_PATTERN_STR; + "(TargetDuration\\s*[<>=]+\\s*duration\\(['\"](\\d+[sSmMhH]+)['\"]\\))"; + private static final String DEFINITION_PATTERN_STR = "(.+)\\s*(?:;)\\s*" + DURATION_PATTERN_STR; private static final Pattern DEFINITION_PATTERN = Pattern.compile(DEFINITION_PATTERN_STR); public enum TriggerState { @@ -56,10 +56,10 @@ public SmartTrigger(String expression, String templateName) { this.state = TriggerState.NEW; Matcher m = DEFINITION_PATTERN.matcher(expression); if (m.matches()) { - triggerCondition = m.group(1); - durationConstraint = m.group(2).replaceAll("'", "\""); + triggerCondition = m.group(1).strip(); + durationConstraint = m.group(2).replaceAll("'", "\"").strip(); /* Duration.parse requires timestamps in ISO8601 Duration format */ - targetDuration = Duration.parse("PT" + m.group(3)); + targetDuration = Duration.parse("PT" + m.group(3).strip()); } else { triggerCondition = expression; durationConstraint = ""; diff --git a/src/main/java/io/cryostat/agent/triggers/TriggerParser.java b/src/main/java/io/cryostat/agent/triggers/TriggerParser.java index 2909b570..4a0379a8 100644 --- a/src/main/java/io/cryostat/agent/triggers/TriggerParser.java +++ b/src/main/java/io/cryostat/agent/triggers/TriggerParser.java @@ -53,6 +53,7 @@ public List parse(String[] args) { String[] expressions = triggerDefinitions.split(","); for (String s : expressions) { + s = s.strip(); Matcher m = EXPRESSION_PATTERN.matcher(s); if (m.matches()) { String constraintString = m.group(1);