You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by ja...@apache.org on 2023/02/24 15:24:44 UTC

[daffodil] branch main updated: Consider ChoiceGroupRef's open when determining next elements

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

jadams 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 7fd1117e9 Consider ChoiceGroupRef's open when determining next elements
7fd1117e9 is described below

commit 7fd1117e9ab869182110803e8638d1e2b7659af8
Author: Josh Adams <ja...@owlcyberdefense.com>
AuthorDate: Mon Feb 20 11:15:05 2023 -0500

    Consider ChoiceGroupRef's open when determining next elements
    
    When determining possible following elements for a group that is a
    choice, it is important to consider them Open as the group can be shared
    and have multiple contexts. The way things had worked before is we would
    push TermRuntimeData's for each group reference onto the stack when
    looking for the next possible element. However, with since these groups
    are actually choices with required elements in every branch they were
    considered closed and if there was an issue attempting to find a
    following element with the first group ref's TRD we would create an
    InvalidErrorERD instead of continuing down the stack until we got to the
    next group ref.
    
    DAFFODIL-2615
---
 .../daffodil/core/runtime1/TermRuntime1Mixin.scala |  6 +++++-
 .../choice_groups/SharedGroupTestSchema.dfdl.xsd   |  6 +++---
 .../section15/choice_groups/testSharedGroups.tdml  | 22 ++++++++++++++++++++++
 .../section15/choice_groups/TestSharedGroups.scala |  3 ++-
 4 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/TermRuntime1Mixin.scala b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/TermRuntime1Mixin.scala
index 924017f53..f59026592 100644
--- a/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/TermRuntime1Mixin.scala
+++ b/daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/TermRuntime1Mixin.scala
@@ -341,6 +341,7 @@ trait TermRuntime1Mixin { self: Term =>
         }
       }
       Logger.log.debug(s"""
+        NextElementResolver -> this: $this\n
         NextElementResolver -> thisItself: $thisItself\n
         NextElementResolver -> following: $followingLexicalSiblingStreamingUnparserElements""")
       val res: PossibleNextElements =
@@ -354,8 +355,11 @@ trait TermRuntime1Mixin { self: Term =>
           case (Closed(pnes1), Closed(pnes2)) => {
             thisItself // When everything is closed, we only want thisItself and not the entire list of Closed possibilities
           }
-          case (Open(pnes1), Closed(pnes2)) => {
+          case (Open(pnes1), Closed(pnes2)) if !this.isInstanceOf[ChoiceGroupRef] => {
             // If there are optional elements before a required element, the whole sequence is considered closed
+            // unless this is a ChoiceGroupRef as the group could be shared and may not have the appropriate
+            // context to find the expected following element. By not closing when it is a ChoiceGroupRef we
+            // allow other contexts to be tried if necessary.
             Closed((pnes1 ++ pnes2).distinct)
           }
           case (poss1, poss2) => {
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd
index c487088ed..943ef9eef 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd
@@ -74,7 +74,7 @@
   <group name="check">
     <choice dfdl:choiceDispatchKey="{ 'V' }">
       <sequence dfdl:choiceBranchKey="V"/>
-      <element dfdl:choiceBranchKey="I" name="invalid" type="ex:str0"/>
+      <element dfdl:choiceBranchKey="I" name="not_valid" type="ex:str0"/>
     </choice>
   </group>
 
@@ -87,8 +87,8 @@
   <group name="check_b">
     <choice dfdl:choiceDispatchKey="{ 'V' }">
       <sequence dfdl:choiceBranchKey="V"/>
-      <element dfdl:choiceBranchKey="I" name="invalid" type="ex:str0"/>
+      <element dfdl:choiceBranchKey="I" name="not_valid" type="ex:str0"/>
     </choice>
   </group>
 
-</schema>
\ No newline at end of file
+</schema>
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/testSharedGroups.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/testSharedGroups.tdml
index 4e3f02bf9..43a92e5b0 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/testSharedGroups.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/testSharedGroups.tdml
@@ -55,5 +55,27 @@
     </infoset>
   </unparserTestCase>
 
+  <unparserTestCase name="badElement"
+                    model="org/apache/daffodil/section15/choice_groups/SharedGroupTestSchema.dfdl.xsd"
+                    root="msg">
+    <document>2XA</document>
+    <infoset>
+      <dfdlInfoset>
+        <ex:msg xmlns:ex="http://example.com" xmlns="">
+          <messageID>2</messageID>
+          <nack>X</nack>
+          <badElement>X</badElement>
+          <nackInfo>A</nackInfo>
+        </ex:msg>
+      </dfdlInfoset>
+    </infoset>
+    <errors>
+      <error>Expected element</error>
+      <error>nackInfo</error>
+      <error>received element</error>
+      <error>(invalid)</error>
+      <error>badElement</error>
+    </errors>
+  </unparserTestCase>
 
 </testSuite>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestSharedGroups.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestSharedGroups.scala
index bc3b5fcc6..54e617e77 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestSharedGroups.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section15/choice_groups/TestSharedGroups.scala
@@ -36,6 +36,7 @@ class TestSharedGroups {
 
   @Test def testShowsSharedGroupOkFirstUse() = { runner.runOneTest("Ack") }
   // DAFFODIL-2615 - shared groups problem
-  // @Test def testShowsSharedGroupFailsSecondUse() = { runner.runOneTest("Nack") }
+  @Test def testShowsSharedGroupFailsSecondUse() = { runner.runOneTest("Nack") }
+  @Test def testShowsSharedGroupBadElement() = { runner.runOneTest("badElement") }
 
 }