Skip to content

Commit

Permalink
Generate warning when node indexed like array
Browse files Browse the repository at this point in the history
- expression '.[...anything...]'' generates warning
- update tests with expression to demonstrate warning

DAFFODIL-2773
  • Loading branch information
olabusayoT committed Sep 30, 2024
1 parent e02ae7f commit ae7ac58
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.lang.{ Long => JLong }
import scala.xml.NamespaceBinding

import org.apache.daffodil.core.dpath._
import org.apache.daffodil.lib.api.WarnID
import org.apache.daffodil.lib.exceptions.Assert
import org.apache.daffodil.lib.schema.annotation.props.Found
import org.apache.daffodil.lib.util.DPathUtil
Expand Down Expand Up @@ -235,6 +236,16 @@ class ExpressionCompiler[T <: AnyRef] extends ExpressionCompilerBase[T] {
compileInfoWhereExpressionWasLocated.SDE(msg, exprOrLiteral)
}

if (expr.contains(".[") && expr.matches(".*\\.\\[.*].*")) {
// checks that only exprs containing the starting part of the problematic expression
// gets the regex check checking that it contains '.[...anything...]'
host.SDW(
WarnID.NodeIndexedLikeArray,
"Expression contains indexing on a node element: %s.",
expr
)
}

val compiler = new DFDLPathExpressionParser[T](
qn,
nodeInfoKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@
<xs:enumeration value="layerCompileWarning" />
<xs:enumeration value="multipleChoiceBranches" />
<xs:enumeration value="namespaceDifferencesOnly" />
<xs:enumeration value="nodeIndexedLikeArray" />
<xs:enumeration value="noEmptyDefault" />
<xs:enumeration value="nonExpressionPropertyValueLooksLikeExpression" />
<xs:enumeration value="patternEncodingSlashW" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,24 +510,35 @@

</tdml:defineSchema>

<tdml:parserTestCase name="test_array_self_expr1" model="arraySchema" root="r">
<tdml:parserTestCase name="test_array_self_expr1" model="arraySchema" root="r" ignoreUnexpectedWarnings="false">
<tdml:document>1|2|3</tdml:document>
<tdml:infoset>
<tdml:dfdlInfoset>
<ex:r>
<e1>1</e1><e1>2</e1><e1>3</e1>
</ex:r>
</tdml:dfdlInfoset>
</tdml:infoset>
<tdml:errors>
<tdml:error>Parse Error</tdml:error>
<tdml:error>Assertion expression failed</tdml:error>
</tdml:errors>
<tdml:warnings>
<tdml:warning>Schema Definition Warning</tdml:warning>
<tdml:warning>Expression contains</tdml:warning>
<tdml:warning>indexing</tdml:warning>
<tdml:warning>node element</tdml:warning>
<tdml:warning>.[1]</tdml:warning>
</tdml:warnings>
</tdml:parserTestCase>

<tdml:parserTestCase name="test_array_self_expr2" model="arraySchema" root="rx">
<tdml:parserTestCase name="test_array_self_expr2" model="arraySchema" root="rx" ignoreUnexpectedWarnings="false">
<tdml:document>1</tdml:document>
<tdml:errors>
<tdml:error>Parse Error</tdml:error>
<tdml:error>Assertion failed</tdml:error>
<tdml:error>42</tdml:error>
</tdml:errors>
<tdml:warnings>
<tdml:warning>Schema Definition Warning</tdml:warning>
<tdml:warning>Expression contains</tdml:warning>
<tdml:warning>indexing</tdml:warning>
<tdml:warning>node element</tdml:warning>
<tdml:warning>.[1]</tdml:warning>
</tdml:warnings>
</tdml:parserTestCase>

<tdml:parserTestCase name="setVariable_neg_01"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class TestDFDLExpressions3 {
// @Test def test_polymorphic_expr_5() { runner.runOneTest("test_polymorphic_expr_5") }
// @Test def test_polymorphic_expr_6() { runner.runOneTest("test_polymorphic_expr_6") }

// DAFFODIL-2182
// @Test def test_array_self_expr1() { runner.runOneTest("test_array_self_expr1") }
@Test def test_array_self_expr1(): Unit = { runner.runOneTest("test_array_self_expr1") }
@Test def test_array_self_expr2(): Unit = { runner.runOneTest("test_array_self_expr2") }

@Test def test_setVariable_neg_01(): Unit = { runner.runOneTest("setVariable_neg_01") }
Expand Down

0 comments on commit ae7ac58

Please sign in to comment.