Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce HiddenGroupRef not being model group of Complex Type #1380

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 @@ 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. " +
"Wrap the hiddenGroupRef sequence in an empty sequence instead."
)
}
}
}

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")
}
}