Skip to content

Commit

Permalink
Fix a bug in FHIRPath that caused children() to include the nodes in …
Browse files Browse the repository at this point in the history
…the input collection if they are primitive types.

PiperOrigin-RevId: 650323751
  • Loading branch information
Quarz0 authored and copybara-github committed Jul 8, 2024
1 parent 265b40f commit d36e6b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cc/google/fhir/fhir_path/fhir_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,9 @@ class ChildrenFunction : public ZeroParameterFunctionNode {

for (const WorkspaceMessage& child : child_results) {
const Descriptor* descriptor = child.Message()->GetDescriptor();
if (IsPrimitive(descriptor)) {
continue;
}
for (int i = 0; i < descriptor->field_count(); i++) {
std::vector<const Message*> messages;
FHIR_RETURN_IF_ERROR(
Expand Down
5 changes: 5 additions & 0 deletions cc/google/fhir/fhir_path/fhir_path_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ TYPED_TEST(FhirPathTest, TestFunctionChildren) {
UnorderedElementsAreArray(
{EqualsProto(structure_definition.snapshot().element(0)),
EqualsProto(structure_definition.differential().element(0))}));

EXPECT_THAT(TestFixture::Evaluate("(1 | 2).children()"), EvalsToEmpty());
}

TYPED_TEST(FhirPathTest, TestFunctionDescendants) {
Expand All @@ -763,6 +765,9 @@ TYPED_TEST(FhirPathTest, TestFunctionDescendants) {
EqualsProto(structure_definition.differential().element(0)),
EqualsProto(
structure_definition.differential().element(0).label())}));

EXPECT_THAT(TestFixture::Evaluate("('foo' | 'bar').descendants()"),
EvalsToEmpty());
}

TYPED_TEST(FhirPathTest, TestFunctionDescendantsOnEmptyCollection) {
Expand Down

0 comments on commit d36e6b2

Please sign in to comment.