From b25f364369c8b6d795c4f384fafd02209668677c Mon Sep 17 00:00:00 2001 From: Kevin Dougan SmileCDR <72025369+KevinDougan-SmileCDR@users.noreply.github.com> Date: Fri, 24 Feb 2023 14:05:07 -0500 Subject: [PATCH] Fix - POST Bundle With ifNoneExist Clause Incorrectly Rejected With Invalid Match URL ERROR (#4588) * Add a failing Unit Test and a changelog. * Fixed the regex to accept the dash character. --- .../4580-fix-basetransactionprocessor-matchurlregex.yaml | 4 ++++ .../fhir/storage/test/BaseTransactionProcessorTest.java | 8 ++++++++ .../ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4580-fix-basetransactionprocessor-matchurlregex.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4580-fix-basetransactionprocessor-matchurlregex.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4580-fix-basetransactionprocessor-matchurlregex.yaml new file mode 100644 index 00000000000..9adcf06c06d --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_6_0/4580-fix-basetransactionprocessor-matchurlregex.yaml @@ -0,0 +1,4 @@ +--- +type: fix +issue: 4580 +title: "Fix the BaseTransactionProcessor.UNQUALIFIED_MATCH_URL_START REGEX so that it correctly matches patterns that contain dashes in them." diff --git a/hapi-fhir-storage-test-utilities/src/test/java/ca/uhn/fhir/storage/test/BaseTransactionProcessorTest.java b/hapi-fhir-storage-test-utilities/src/test/java/ca/uhn/fhir/storage/test/BaseTransactionProcessorTest.java index abb20c6fab5..a7ce2524178 100644 --- a/hapi-fhir-storage-test-utilities/src/test/java/ca/uhn/fhir/storage/test/BaseTransactionProcessorTest.java +++ b/hapi-fhir-storage-test-utilities/src/test/java/ca/uhn/fhir/storage/test/BaseTransactionProcessorTest.java @@ -27,6 +27,7 @@ import org.hl7.fhir.r4.model.IdType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class BaseTransactionProcessorTest { @@ -102,4 +103,11 @@ public class BaseTransactionProcessorTest { assertEquals(input, outcome); } + @Test + void testUnqualifiedMatchUrlStart_RegexPatternMatches() { + String matchUrl = "patient-first-identifier=MRN%7C123456789"; + boolean matchResult = BaseTransactionProcessor.UNQUALIFIED_MATCH_URL_START.matcher(matchUrl).find(); + assertTrue(matchResult, "Failed to find a Regex match using Url '" + matchUrl + "'"); + } + } diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java index 43c1de97dab..ec4bc5ed248 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java @@ -137,7 +137,7 @@ public abstract class BaseTransactionProcessor { public static final String URN_PREFIX = "urn:"; public static final String URN_PREFIX_ESCAPED = UrlUtil.escapeUrlParam(URN_PREFIX); - public static final Pattern UNQUALIFIED_MATCH_URL_START = Pattern.compile("^[a-zA-Z0-9_]+="); + public static final Pattern UNQUALIFIED_MATCH_URL_START = Pattern.compile("^[a-zA-Z0-9_-]+="); public static final Pattern INVALID_PLACEHOLDER_PATTERN = Pattern.compile("[a-zA-Z]+:.*"); private static final Logger ourLog = LoggerFactory.getLogger(BaseTransactionProcessor.class); @Autowired