Skip to content

Commit

Permalink
Fix Incorrect Lengths SDEs on Computed Element with LengthKind Implicit
Browse files Browse the repository at this point in the history
- currently we SDE on IVC elements with lengthKind=implicit, which is incorrect, as it's a computed element. We update the code to check the element is represented before doing those checks. If it is, we do the check.
- add condition that checks for IVC before doing the check
- add tests

DAFFODIL-2806
  • Loading branch information
olabusayoT committed Oct 14, 2024
1 parent b5d6914 commit d61a1e4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1007,13 +1007,19 @@ trait ElementBase
"The length facet or minLength/maxLength facets are not allowed on types derived from type %s.\nThey are allowed only on types derived from string and hexBinary.",
pt.name
)
val res = (hasLength, hasMinLength, hasMaxLength, lengthKind) match {
case (true, false, false, _) => (r.lengthValue, r.lengthValue)
case (true, _, _, _) =>
val res = (
hasLength,
hasMinLength,
hasMaxLength,
lengthKind,
isRepresented
) match {
case (true, false, false, _, _) => (r.lengthValue, r.lengthValue)
case (true, _, _, _, _) =>
Assert.invariantFailed(
"Facet length cannot be defined with minLength and maxLength facets"
)
case (false, true, true, LengthKind.Implicit) => {
case (false, true, true, LengthKind.Implicit, true) => {
schemaDefinitionUnless(
r.minLengthValue.compareTo(r.maxLengthValue) == 0,
"The minLength and maxLength must be equal for type %s with lengthKind='implicit'. Values were minLength of %s, maxLength of %s.",
Expand All @@ -1023,7 +1029,7 @@ trait ElementBase
)
(r.minLengthValue, r.maxLengthValue)
}
case (false, true, true, _) => {
case (false, true, true, _, _) => {
schemaDefinitionWhen(
r.minLengthValue.compareTo(r.maxLengthValue) > 0,
// always true, so we don't bother to specify the type in the message.
Expand All @@ -1033,13 +1039,13 @@ trait ElementBase
)
(r.minLengthValue, r.maxLengthValue)
}
case (false, _, _, LengthKind.Implicit) =>
case (false, _, _, LengthKind.Implicit, true) =>
SDE(
"When lengthKind='implicit', both minLength and maxLength facets must be specified."
)
case (false, false, true, _) => (zeroBD, r.maxLengthValue)
case (false, false, false, _) => (zeroBD, unbBD)
case (false, true, false, _) => (r.minLengthValue, unbBD)
case (false, false, true, _, _) => (zeroBD, r.maxLengthValue)
case (false, false, false, _, _) => (zeroBD, unbBD)
case (false, true, false, _, _) => (r.minLengthValue, unbBD)
case _ => Assert.impossible()
}
res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1407,4 +1407,28 @@
</tdml:errors>
</tdml:parserTestCase>

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

<xs:simpleType name="valueType">
<xs:restriction base="xs:string">
<xs:maxLength value="13"/>
</xs:restriction>
</xs:simpleType>

<xs:element name="value" type="ex:valueType"
dfdl:inputValueCalc="{ 'Hello World' }"/>
</tdml:defineSchema>

<tdml:parserTestCase name="IVC_ignored_length_checks"
root="value" model="ignoreLengthKindImplicitLengthChecksOnIVCElements">

<tdml:document/>
<tdml:infoset>
<tdml:dfdlInfoset>
<ex:value>Hello World</ex:value>
</tdml:dfdlInfoset>
</tdml:infoset>
</tdml:parserTestCase>
</tdml:testSuite>
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,9 @@ class TestInputValueCalc {
runner.runOneTest("InputValueCalc_array_elem")
}
// @Test def test_InputValueCalc_global_elem() { runner.runOneTest("InputValueCalc_global_elem") }

// DFDL-2806
@Test def test_IVC_ignored_length_checks(): Unit = {
runner.runOneTest("IVC_ignored_length_checks")
}
}

0 comments on commit d61a1e4

Please sign in to comment.