From 7d3f34b0ca0fa9cd33b69a38abaf6ef412b8af87 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 12 Jan 2022 17:44:11 +1100 Subject: [PATCH] fix error in FHIRPath handling for incomplete FHIR Path expressions --- .../src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java | 3 +++ .../src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java | 4 +++- org.hl7.fhir.utilities/src/main/resources/Messages.properties | 2 +- .../org/hl7/fhir/validation/instance/InstanceValidator.java | 3 ++- pom.xml | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java index 6f4d3ad37..60dd6958f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java @@ -519,5 +519,8 @@ public class FHIRLexer { public int getCurrentStart() { return currentStart; } + public String getSource() { + return source; + } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java index cc9cc7b53..bcf77b7d9 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java @@ -1000,7 +1000,9 @@ public class FHIRPathEngine { wrapper.setProximal(proximal); } - if (lexer.isConstant()) { + if (lexer.getCurrent() == null) { + throw lexer.error("Expression terminated unexpectedly"); + } else if (lexer.isConstant()) { boolean isString = lexer.isStringConstant(); if (!isString && (lexer.getCurrent().startsWith("-") || lexer.getCurrent().startsWith("+"))) { // the grammar says that this is a unary operation; it affects the correct processing order of the inner operations diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties index 146063cba..a6bdae0e1 100644 --- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties +++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties @@ -246,7 +246,7 @@ All_observations_should_have_a_performer = All observations should have a perfor All_observations_should_have_a_subject = All observations should have a subject Unable_to_resolve_slice_matching__no_fixed_value_or_required_value_set = Unable to resolve slice matching - no fixed value or required value set Unable_to_resolve_slice_matching__slice_matching_by_value_set_not_done = Unable to resolve slice matching - slice matching by value set not done -Problem_processing_expression__in_profile__path__ = Problem processing expression {0} in profile {1} path {2}: {3} +Problem_processing_expression__in_profile__path__ = Problem processing expression ''{0}'' in profile ''{1}'' at path ''{2}'': {3} Unable_to_find_element_with_id_ = Unable to find element with id ''{0}'' Slice_encountered_midway_through_set_path___id___ = Slice encountered midway through set (path = {0}, id = {1}); {2} Unable_to_resolve_actual_type_ = Unable to resolve actual type {0} diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 38ec59016..8101d65cf 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -5490,7 +5490,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat try { n = fpe.parse(fixExpr(inv.getExpression(), inv.getKey())); } catch (FHIRLexerException e) { - throw new FHIRException(context.formatMessage(I18nConstants.PROBLEM_PROCESSING_EXPRESSION__IN_PROFILE__PATH__, inv.getExpression(), profile.getUrl(), path, e.getMessage())); + rule(errors, IssueType.INVARIANT, element.line(), element.col(), path, false, I18nConstants.PROBLEM_PROCESSING_EXPRESSION__IN_PROFILE__PATH__, inv.getExpression(), profile.getUrl(), path, e.getMessage()); + return; } timeTracker.fpe(t); inv.setUserData("validator.expression.cache", n); diff --git a/pom.xml b/pom.xml index 1d1166222..e6005c6b1 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.1.0 - 1.1.86 + 1.1.87-SNAPSHOT 5.7.1 1.7.1 3.0.0-M5