Merge branch 'master' into gg-202108-misc-1
This commit is contained in:
commit
d4d827f2f3
|
@ -0,0 +1 @@
|
|||
* Fixed ID verification issues for resources
|
|
@ -0,0 +1,32 @@
|
|||
package org.hl7.fhir.r5.formats;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class FormatUtilitiesTest {
|
||||
|
||||
private static Stream<Arguments> provideIdsWithOutcomes() {
|
||||
return Stream.of(
|
||||
Arguments.of("1234", true),
|
||||
Arguments.of("12-34", true),
|
||||
Arguments.of("12_34", false),
|
||||
Arguments.of("12.34", true),
|
||||
Arguments.of("12/34", false),
|
||||
Arguments.of("1234#", false),
|
||||
Arguments.of("31415926535897932384626433832795028841971693993751058209749445923", false) // 65 digits
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideIdsWithOutcomes")
|
||||
void isValidIdTest(String id, boolean expected) {
|
||||
Assertions.assertEquals(FormatUtilities.isValidId(id), expected);
|
||||
}
|
||||
}
|
|
@ -5178,31 +5178,13 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
Element eid = element.getNamedChild(ID);
|
||||
if (eid.getProperty() != null && eid.getProperty().getDefinition() != null && eid.getProperty().getDefinition().getBase().getPath().equals("Resource.id")) {
|
||||
NodeStack ns = stack.push(eid, -1, eid.getProperty().getDefinition(), null);
|
||||
rule(errors, IssueType.INVALID, eid.line(), eid.col(), ns.getLiteralPath(), idFormattedCorrectly(eid.getValue()), I18nConstants.RESOURCE_RES_ID_MALFORMED);
|
||||
rule(errors, IssueType.INVALID, eid.line(), eid.col(), ns.getLiteralPath(), FormatUtilities.isValidId(eid.primitiveValue()), I18nConstants.RESOURCE_RES_ID_MALFORMED);
|
||||
}
|
||||
}
|
||||
start(hostContext, errors, element, element, defn, stack); // root is both definition and type
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FHIR IDs are constrained to any combination of upper- or lower-case ASCII letters ('A'..'Z', and 'a'..'z',
|
||||
* numerals ('0'..'9'), '-' and '.', with a length limit of 64 characters. (This might be an integer, an un-prefixed
|
||||
* OID, UUID or any other identifier pattern that meets these constraints.)
|
||||
*
|
||||
* As a heads up, a null String will pass this check.
|
||||
*
|
||||
* @param id The id to verify conformance to specification requirements.
|
||||
* @return {@link Boolean#TRUE} if the passed in ID is a valid resource ID, {@link Boolean#FALSE} otherwise.
|
||||
*/
|
||||
protected static boolean idFormattedCorrectly(@Nonnull String id) {
|
||||
String idRegex = "[A-Za-z0-9\\-\\.]{1,64}";
|
||||
Pattern pattern = Pattern.compile(idRegex);
|
||||
Matcher matcher = pattern.matcher(id);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
|
||||
private NodeStack getFirstEntry(NodeStack bundle) {
|
||||
List<Element> list = new ArrayList<Element>();
|
||||
bundle.getElement().getNamedChildren(ENTRY, list);
|
||||
|
|
|
@ -13,21 +13,5 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
class InstanceValidatorTest {
|
||||
|
||||
|
||||
private static Stream<Arguments> provideIdsWithOutcomes() {
|
||||
return Stream.of(
|
||||
Arguments.of("1234", true),
|
||||
Arguments.of("12-34", true),
|
||||
Arguments.of("12_34", false),
|
||||
Arguments.of("12.34", true),
|
||||
Arguments.of("12/34", false),
|
||||
Arguments.of("1234#", false),
|
||||
Arguments.of("31415926535897932384626433832795028841971693993751058209749445923", false) // 65 digits
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideIdsWithOutcomes")
|
||||
void idFormattedCorrectly(String id, boolean expected) {
|
||||
Assertions.assertEquals(InstanceValidator.idFormattedCorrectly(id), expected);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue