FirelyTeam / firely-net-sdk

The official Firely .NET SDK for HL7 FHIR
Other
824 stars 342 forks source link

Patch FP constraints because of wrong interpretation of `matches()` #2013

Closed ewoutkramer closed 2 years ago

ewoutkramer commented 2 years ago

Describe the bug This is not a bug per se, but as a result of a recent discussion on how the FP function matches() work, it's become clear that a few FP constraints in the HL7 FHIR spec are incorrect. To be exact: matches() will match any substring of a string with a pattern, while both Grahame and I had assumed this will match the whole string. This in turn has led to a few incorrect FP constraints being present in the spec.

To Reproduce In fact, the .NET SDK has implemented matches() correctly (as the .NET Regex matches does the "right" thing), it's just that some constraints have assumed that the regex matches the whole string, rather than a substring.

At this moment the constraints sdf-0, eld-19 and eld-20 are in error.

Expected behavior To fix this, we need to wrap a small number of constraints in ^ and $ to make them work correctly. This will ensure the constraints match the WHOLE string, not a substring.

Additional context See https://chat.fhir.org/#narrow/stream/179266-fhirpath/topic/Matches.20question for the full discussion.

ewoutkramer commented 2 years ago

Since this will be fixed in future versions, we'd better check whether the regexes already are wrapped with ^$ before we "repair" them as a defensive measure.