Skip to content

Commit

Permalink
Enforce HiddenGroupRef not being model group of Complex Type
Browse files Browse the repository at this point in the history
- 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 wrap the HGR in a regular sequence
- add test to show SDE
- update tests with HiddenGroupRef as model group of ComplexType

DAFFODIL-2419
  • Loading branch information
olabusayoT committed Nov 21, 2024
1 parent 861df2a commit 6248093
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ object ModelGroupFactory {
// a SequenceGroupRef or ChoiceGroupRef, with isHidden = true. So this
// temporary sequence will be discarded after this.
seq.checkHiddenGroupRefHasNoChildren
seq.checkHiddenGroupRefNotChildOfComplexType
//
// construct the group ref XML, then recursively process that,
// but set flag so it will be hidden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ trait SequenceDefMixin
}
}

lazy val checkHiddenGroupRefNotChildOfComplexType: Unit = {
if (hiddenGroupRefOption.isDefined) {
optLexicalParent.collect { case _: ComplexTypeBase =>
schemaDefinitionError(
"A complex type cannot have a sequence with a hiddenGroupRef as its model group"
)
}
}
}

final lazy val hiddenGroupRefXML = LV('hiddenGroupRefXML) {
val Found(qname, _, _, _) = hiddenGroupRefOption
// synthesize a group reference here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class TestRefMap {
</xs:group>
<xs:element name="r1" type="ex:ct1"/>
<xs:complexType name="ct1">
<xs:sequence dfdl:hiddenGroupRef="ex:g1"/>
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="ex:g1"/>
</xs:sequence>
</xs:complexType>
<xs:group name="g1">
<xs:choice>
Expand All @@ -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)
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,32 @@
</tdml:errors>
</tdml:unparserTestCase>

<tdml:defineSchema name="ComplexTypeWithHiddenGroupRefSequence">
<xs:include
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
<dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" />

<xs:group name="s4">
<xs:sequence>
<xs:element name="f" type="xs:int" dfdl:outputValueCalc="{6}"/>
</xs:sequence>
</xs:group>
<xs:element name="e1">
<xs:complexType>
<xs:sequence dfdl:hiddenGroupRef="ex:s4"/>
</xs:complexType>
</xs:element>
</tdml:defineSchema>

<tdml:parserTestCase name="ComplexTypeWithHiddenGroupRefSequence1" root="e1"
model="ComplexTypeWithHiddenGroupRefSequence">
<tdml:document>7</tdml:document>
<tdml:errors>
<tdml:error>Schema Definition Error</tdml:error>
<tdml:error>complex type cannot have</tdml:error>
<tdml:error>sequence with a hiddenGroupRef</tdml:error>
<tdml:error>model group</tdml:error>
</tdml:errors>
</tdml:parserTestCase>
</tdml:testSuite>

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
<xs:sequence>
<xs:element name="h">
<xs:complexType>
<xs:sequence dfdl:hiddenGroupRef="ex:s1" />
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="ex:s1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
dfdl:outputValueCalc="{ 1 }" />
<xs:element name="h">
<xs:complexType>
<xs:sequence dfdl:hiddenGroupRef="ex:c1" />
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="ex:c1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
Expand All @@ -119,7 +121,9 @@
dfdl:outputValueCalc="{ 'hello' }" />
<xs:element name="h">
<xs:complexType>
<xs:sequence dfdl:hiddenGroupRef="ex:c1" />
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="ex:c1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
Expand Down Expand Up @@ -160,7 +164,9 @@
<xs:sequence>
<xs:element name="g">
<xs:complexType>
<xs:sequence dfdl:hiddenGroupRef="ex:c3" />
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="ex:c3" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand All @@ -178,7 +184,9 @@
<xs:sequence>
<xs:element name="g">
<xs:complexType>
<xs:sequence dfdl:hiddenGroupRef="ex:c1" />
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="ex:c1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4919,7 +4919,9 @@
<xs:element name="name" type="xs:string" dfdl:lengthKind="delimited"/>
<xs:element name="data">
<xs:complexType>
<xs:sequence dfdl:hiddenGroupRef="ex:hiddenData"/>
<xs:sequence>
<xs:sequence dfdl:hiddenGroupRef="ex:hiddenData"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ class TestHiddenSequences {
@Test def test_invalidGroupDefWithHiddenSequenceModelGroup(): Unit = {
runnerNoValidate.runOneTest("invalidGroupDefWithHiddenSequenceModelGroup")
}

@Test def test_ComplexTypeWithHiddenGroupRefSequence1(): Unit = {
runnerNoValidate.runOneTest("ComplexTypeWithHiddenGroupRefSequence1")
}
}

0 comments on commit 6248093

Please sign in to comment.