This is an automated email from the ASF dual-hosted git repository.

olabusayo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new d61a1e4aa Fix Incorrect Lengths SDEs on Computed Element with 
LengthKind Implicit
d61a1e4aa is described below

commit d61a1e4aa39be45f569b9f4d958f1a77af8c1ccd
Author: olabusayoT <[email protected]>
AuthorDate: Thu Oct 10 16:29:33 2024 -0400

    Fix Incorrect Lengths SDEs on Computed Element with LengthKind Implicit
    
    - 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
---
 .../apache/daffodil/core/dsom/ElementBase.scala    | 24 ++++++++++++++--------
 .../calc_value_properties/inputValueCalc.tdml      | 24 ++++++++++++++++++++++
 .../calc_value_properties/TestInputValueCalc.scala |  5 +++++
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementBase.scala 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementBase.scala
index d057b696c..3992415bc 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementBase.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/dsom/ElementBase.scala
@@ -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.",
@@ -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.
@@ -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
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section17/calc_value_properties/inputValueCalc.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section17/calc_value_properties/inputValueCalc.tdml
index 16522b2ed..b5c7433f7 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section17/calc_value_properties/inputValueCalc.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section17/calc_value_properties/inputValueCalc.tdml
@@ -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>
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section17/calc_value_properties/TestInputValueCalc.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section17/calc_value_properties/TestInputValueCalc.scala
index 307bf00a4..0e630b0b8 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section17/calc_value_properties/TestInputValueCalc.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section17/calc_value_properties/TestInputValueCalc.scala
@@ -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")
+  }
 }

Reply via email to