From c29df47494e9fc89991debd5948155c6aef3bcef Mon Sep 17 00:00:00 2001 From: atuonufure Date: Tue, 15 Aug 2023 09:20:45 +0200 Subject: [PATCH] Update substring invocation --- fhirpathpy/engine/invocations/strings.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fhirpathpy/engine/invocations/strings.py b/fhirpathpy/engine/invocations/strings.py index cf2bdcf..5e1191c 100644 --- a/fhirpathpy/engine/invocations/strings.py +++ b/fhirpathpy/engine/invocations/strings.py @@ -20,13 +20,18 @@ def index_of(ctx, coll, substr): def substring(ctx, coll, start, length=None): string = ensure_string_singleton(coll) + + if isinstance(start, list) or start is None: + return [] + start = int(start) + if start < 0 or start >= len(string): + return [] - if length is None: + if length is None or length == []: return string[start:] - length = int(length) - return string[start : start + length] + return string[start : start + int(length)] def starts_with(ctx, coll, prefix):