From ca972f8d7b24ad08fbbb7662d6daafa78a0edf7c Mon Sep 17 00:00:00 2001 From: Carlos Amengual Date: Tue, 17 Oct 2023 13:32:44 +0200 Subject: [PATCH] Prevent NPEs in previous commit --- .../transcoder/util/CSSTranscodingHelper.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/util/CSSTranscodingHelper.java b/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/util/CSSTranscodingHelper.java index 9f492434c..9eab8ad58 100644 --- a/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/util/CSSTranscodingHelper.java +++ b/echosvg-transcoder/src/main/java/io/sf/carte/echosvg/transcoder/util/CSSTranscodingHelper.java @@ -1138,22 +1138,25 @@ public boolean supports(SelectorList selectors) { } private boolean supports(Selector selector) { - switch (selector.getSelectorType()) { - case CHILD: - case DESCENDANT: - case DIRECT_ADJACENT: - case SUBSEQUENT_SIBLING: - CombinatorSelector combSel = (CombinatorSelector) selector; - return supports(combSel.getSelector()) && supports(combSel.getSecondSelector()); - case CONDITIONAL: - ConditionalSelector condSel = (ConditionalSelector) selector; - return supports(condSel.getSimpleSelector()) - && supports(condSel.getCondition()); - case COLUMN_COMBINATOR: - return false; - default: - return true; + if (selector != null) { + switch (selector.getSelectorType()) { + case CHILD: + case DESCENDANT: + case DIRECT_ADJACENT: + case SUBSEQUENT_SIBLING: + CombinatorSelector combSel = (CombinatorSelector) selector; + return supports(combSel.getSelector()) + && supports(combSel.getSecondSelector()); + case CONDITIONAL: + ConditionalSelector condSel = (ConditionalSelector) selector; + return supports(condSel.getSimpleSelector()) + && supports(condSel.getCondition()); + case COLUMN_COMBINATOR: + return false; + default: + } } + return true; } private boolean supports(Condition condition) { @@ -1164,7 +1167,8 @@ private boolean supports(Condition condition) { && supports(combCond.getSecondCondition()); case SELECTOR_ARGUMENT: ArgumentCondition argCond = (ArgumentCondition) condition; - return supports(argCond.getSelectors()); + SelectorList selist = argCond.getSelectors(); + return selist == null || supports(selist); default: return true; }