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

slawrence 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 e467498ea Disable constant length facet check for inputValueCalc 
elements
e467498ea is described below

commit e467498ea9ad4485502428e0f0e1177cb5fe3677
Author: Steve Lawrence <[email protected]>
AuthorDate: Fri Sep 20 12:37:56 2024 -0400

    Disable constant length facet check for inputValueCalc elements
    
    It is possible to have dfdl:lengthKind="explicit" defiend for elements
    with dfdl:inputValueCalc. In that case, ther lengthKidproperty should
    just be ignored. But the logic for checking if a constant length element
    is within facet length bounds did not ignore the property for IVC
    elements, which led to it expecting a dfdl:length and errorer.
    
    To fix this, and addition restriction is added so we only do the check
    for represented elements, i.e. non-IVC elements.
    
    DAFFODIL-2888
---
 .../core/grammar/ElementBaseGrammarMixin.scala     |  7 ++++--
 .../section02/validation_errors/Validation.tdml    | 28 ++++++++++++++++++++++
 .../validation_errors/TestValidationErr.scala      |  3 +++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
index d48a95932..45d4bf0b3 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala
@@ -1625,9 +1625,12 @@ trait ElementBaseGrammarMixin
      * Warn if a type respects minLength/maxLength/length facets and we can 
calculate that the
      * infoset length will be out of range of the facet values. Note that we 
can only do this in
      * specific cases, like when the length and encoding properties are 
constant and the
-     * encoding is fixed width characters.
+     * encoding is fixed width characters. Note that IVC ignores explicit 
length so we only do
+     * this for represented elements.
      */
-    if ((lengthKind eq LengthKind.Explicit) && (hasLength || hasMinLength || 
hasMaxLength)) {
+    if (
+      isRepresented && (lengthKind eq LengthKind.Explicit) && (hasLength || 
hasMinLength || hasMaxLength)
+    ) {
       val optInfosetLen = elementLengthInBitsEv.optConstant.flatMap { 
maybeKnownLenInBits =>
         if (maybeKnownLenInBits.isDefined) {
           val len = maybeKnownLenInBits.get
diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/section02/validation_errors/Validation.tdml
 
b/daffodil-test/src/test/resources/org/apache/daffodil/section02/validation_errors/Validation.tdml
index 85c421887..243e6ef44 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/section02/validation_errors/Validation.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/section02/validation_errors/Validation.tdml
@@ -411,6 +411,18 @@
       </xs:simpleType>
     </xs:element>
 
+    <!--
+      dfdl:lengthKind will be ignored when used by IVC elements, but could
+      potentially be used by non-IVC elements that define dfdl:length
+    -->
+    <xs:simpleType name="str" dfdl:lengthKind="explicit">
+      <xs:restriction base="xs:string">
+        <xs:maxLength value="5" />
+      </xs:restriction>
+    </xs:simpleType>
+
+    <xs:element name="e4" type="ex:str" dfdl:inputValueCalc="{ '123456' }" />
+
   </tdml:defineSchema>
 
     <tdml:defineSchema name="TestFacets">
@@ -2153,6 +2165,22 @@
 
     </tdml:parserTestCase>
 
+    <tdml:parserTestCase name="validation_inputValueCalc_08"
+                         root="e4" model="inputValueCalc"
+                         description="Section 17 - the value created using 
inputValueCalc is validated using length facets"
+                         validation="on">
+        <tdml:document></tdml:document>
+        <tdml:infoset>
+            <tdml:dfdlInfoset>
+                <e4>123456</e4>
+            </tdml:dfdlInfoset>
+        </tdml:infoset>
+        <tdml:validationErrors>
+            <tdml:error>Validation Error</tdml:error>
+            <tdml:error>failed facet checks due to: facet maxLength 
(5)</tdml:error>
+        </tdml:validationErrors>
+    </tdml:parserTestCase>
+
     <tdml:defineSchema name="TestFacets2">
         <xs:include 
schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
         <dfdl:format ref="ex:GeneralFormat" />
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/section02/validation_errors/TestValidationErr.scala
 
b/daffodil-test/src/test/scala/org/apache/daffodil/section02/validation_errors/TestValidationErr.scala
index 0b76641fe..45414b49c 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/section02/validation_errors/TestValidationErr.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/section02/validation_errors/TestValidationErr.scala
@@ -180,6 +180,9 @@ class TestValidationErr {
   @Test def test_validation_inputValueCalc_07(): Unit = {
     runner.runOneTest("validation_inputValueCalc_07")
   }
+  @Test def test_validation_inputValueCalc_08(): Unit = {
+    runner.runOneTest("validation_inputValueCalc_08")
+  }
 
   @Test def test_validation_testFacets_01(): Unit = {
     runner.runOneTest("validation_testFacets_01")

Reply via email to