Skip to content

Commit

Permalink
Merge pull request #1639 from FirelyTeam/fix/1563-use-other-regex-for…
Browse files Browse the repository at this point in the history
…-string-r4

R4: Use a better validation regex for strings
  • Loading branch information
marcovisserFurore authored Feb 25, 2021
2 parents db9253f + 7420fb8 commit d2d7fba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,13 @@ private static void assertElementConstraints(List<ElementDefinition> patientElem
}
}


[Fact]
public void ValidateNonBreakingWhitespaceInString()
{
var value = new FhirString("Non-breaking" + '\u00A0' + "space");
var result = _validator.Validate(value);
Assert.True(result.Success);
}

private class ClearSnapshotResolver : IResourceResolver
{
Expand Down
6 changes: 6 additions & 0 deletions src/Hl7.Fhir.Specification/Validation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ private OperationOutcome validateRegexExtension(IExtendable elementDef, ITypedEl
var pattern = elementDef.GetStringExtension(uri);
if (pattern != null)
{
// See issue https://github.com/FirelyTeam/firely-net-sdk/issues/1563 and https://hl7.org/fhir/datatypes.html#string
// the regex provided by the Fhir standard is not sufficient enough. The regex [\r\n\t\u0020-\uFFFF]* is more recommended
if (instance?.InstanceType == FHIRAllTypes.String.GetLiteral() && pattern == @"[ \r\n\t\S]+")
{
pattern = @"[\r\n\t\u0020-\uFFFF]*";
}
var regex = new Regex(pattern);
var value = toStringRepresentation(instance);
var success = Regex.Match(value, "^" + regex + "$").Success;
Expand Down

0 comments on commit d2d7fba

Please sign in to comment.