Skip to content

Commit

Permalink
strip leading/trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Nov 17, 2023
1 parent 995cc2e commit 27fd831
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/io/cryostat/agent/triggers/SmartTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public List<SmartTrigger> 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);
Expand Down

0 comments on commit 27fd831

Please sign in to comment.