From 48131bf1c69ea9beb3c76f032573b9556994a64a Mon Sep 17 00:00:00 2001
From: olabusayoT <50379531+olabusayoT@users.noreply.github.com>
Date: Thu, 21 Nov 2024 12:32:28 -0500
Subject: [PATCH] Enforce HiddenGroupRef not being model group of Complex Type
- currently we don't check if a hiddenGroupRef is the model group of a complexType, which allows schemas to have them. This check will ensure schemas can't have hiddenGroupRefs as their model group, and instead recommends wrapping the HGR in an empty sequence
- add test to show SDE
- update tests with HiddenGroupRef as model group of ComplexType
DAFFODIL-2419
---
.../daffodil/core/dsom/ComplexTypes.scala | 9 ++++++
.../daffodil/core/dsom/TestRefMap.scala | 10 ++++---
.../sequence_groups/HiddenSequences.tdml | 28 +++++++++++++++++++
.../SequencesWithHiddenRefs.dfdl.xsd | 4 ++-
.../ChoicesInHiddenContexts.dfdl.xsd | 16 ++++++++---
.../section23/dfdl_functions/Functions.tdml | 4 ++-
.../sequence_groups/TestHiddenSequences.scala | 4 +++
7 files changed, 65 insertions(+), 10 deletions(-)
diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ComplexTypes.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ComplexTypes.scala
index 5f8e4cc1cf..3da1dab093 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ComplexTypes.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ComplexTypes.scala
@@ -51,6 +51,15 @@ sealed abstract class ComplexTypeBase(xmlArg: Node, parentArg: SchemaComponent)
s.length == 1,
"A complex type must have exactly one model-group element child which is a sequence, choice, or group reference."
)
+ s.head match {
+ case sgtb: SequenceGroupTermBase =>
+ sgtb.schemaDefinitionWhen(
+ sgtb.isHidden,
+ "A complex type cannot have a sequence with a hiddenGroupRef as its model group. " +
+ "Wrap the hiddenGroupRef sequence in an empty sequence instead."
+ )
+ case _ => // do nothing
+ }
s
}
diff --git a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestRefMap.scala b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestRefMap.scala
index 0918af8e03..3be9ba99f6 100644
--- a/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestRefMap.scala
+++ b/daffodil-core/src/test/scala/org/apache/daffodil/core/dsom/TestRefMap.scala
@@ -163,7 +163,9 @@ class TestRefMap {
-
+
+
+
@@ -176,7 +178,7 @@ class TestRefMap {
val sset = compiler.compileNode(testSchema).sset
val root = sset.root
val comps = root.allComponents
- assertEquals(14, comps.length)
+ assertEquals(15, comps.length)
val refMap = root.refMap
val numEntries = refMap.size
assertEquals(6, numEntries)
@@ -189,8 +191,8 @@ class TestRefMap {
val gref = rootDecl.complexType.modelGroup.asInstanceOf[ChoiceGroupRef]
val Seq((grefSSCD, gdRefSpecs)) = refMap.get(gref.groupDef).get
assertEquals(gref.shortSchemaComponentDesignator, grefSSCD)
- assertEquals(14, root.numComponents)
- assertEquals(14, root.numUniqueComponents)
+ assertEquals(15, root.numComponents)
+ assertEquals(15, root.numUniqueComponents)
}
@Test def testRefMapNonExplosion1(): Unit = {
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/HiddenSequences.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/HiddenSequences.tdml
index 30e41df604..6c11bc3304 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/HiddenSequences.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/HiddenSequences.tdml
@@ -282,4 +282,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 7
+
+ Schema Definition Error
+ complex type cannot have
+ sequence with a hiddenGroupRef
+ model group
+
+
+
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequencesWithHiddenRefs.dfdl.xsd b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequencesWithHiddenRefs.dfdl.xsd
index ad87150b17..0eebd7f58e 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequencesWithHiddenRefs.dfdl.xsd
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequencesWithHiddenRefs.dfdl.xsd
@@ -82,7 +82,9 @@
-
+
+
+
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/ChoicesInHiddenContexts.dfdl.xsd b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/ChoicesInHiddenContexts.dfdl.xsd
index 7ab59b8c7b..8449da74b6 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/ChoicesInHiddenContexts.dfdl.xsd
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/ChoicesInHiddenContexts.dfdl.xsd
@@ -106,7 +106,9 @@
dfdl:outputValueCalc="{ 1 }" />
-
+
+
+
@@ -119,7 +121,9 @@
dfdl:outputValueCalc="{ 'hello' }" />
-
+
+
+
@@ -160,7 +164,9 @@
-
+
+
+
@@ -178,7 +184,9 @@
-
+
+
+
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
index 2ec4badeda..09f9131018 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
@@ -4919,7 +4919,9 @@
-
+
+
+
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestHiddenSequences.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestHiddenSequences.scala
index 42a3dab4d5..25a72a8ffb 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestHiddenSequences.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section14/sequence_groups/TestHiddenSequences.scala
@@ -78,4 +78,8 @@ class TestHiddenSequences {
@Test def test_invalidGroupDefWithHiddenSequenceModelGroup(): Unit = {
runnerNoValidate.runOneTest("invalidGroupDefWithHiddenSequenceModelGroup")
}
+
+ @Test def test_ComplexTypeWithHiddenGroupRefSequence1(): Unit = {
+ runnerNoValidate.runOneTest("ComplexTypeWithHiddenGroupRefSequence1")
+ }
}