Skip to content

Commit bc68935

Browse files
committed
fixup! Fix Bug with valueLength being overwritten after Trim
- update check to captureValueLength in base parser if it's a complex element - update shouldCaptureParseValueLength to use PrimType.String instead of representation Text, since strings valueLengths (and delimited valueLengths) are always handled by value parsers DAFFODIL-2658
1 parent 15ba745 commit bc68935

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

daffodil-core/src/main/scala/org/apache/daffodil/core/runtime1/ElementBaseRuntime1Mixin.scala

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import org.apache.daffodil.core.dsom.PrimitiveType
2424
import org.apache.daffodil.core.dsom.Root
2525
import org.apache.daffodil.core.dsom.SimpleTypeDefBase
2626
import org.apache.daffodil.lib.schema.annotation.props.gen.LengthKind
27-
import org.apache.daffodil.lib.schema.annotation.props.gen.Representation
2827
import org.apache.daffodil.lib.util.Delay
2928
import org.apache.daffodil.lib.util.Maybe
29+
import org.apache.daffodil.runtime1.dpath.NodeInfo.PrimType
3030
import org.apache.daffodil.runtime1.dsom.DPathElementCompileInfo
3131
import org.apache.daffodil.runtime1.processors.ElementRuntimeData
3232
import org.apache.daffodil.runtime1.processors.RuntimeData
@@ -89,17 +89,19 @@ trait ElementBaseRuntime1Mixin { self: ElementBase =>
8989
//
9090
// For complex elements with specified length, value length is captured in
9191
// the specified length parsers, since they handle skipping unused
92-
// element regions. For complex elements, this means lengthKind is not
92+
// element regions, and the length capturing has to be done before that.
93+
// For complex elements, this means lengthKind is not
9394
// implicit or delimited.
9495
//
9596
// So for these cases we do not want to capture value length with the
9697
// Capture{Start,End}OfValueLengthParsers, since those lengths are captured
9798
// by the value parsers
98-
val capturedByParsers =
99-
(isSimpleType && (impliedRepresentation == Representation.Text || lengthKind == LengthKind.Delimited)) ||
99+
val capturedByValueParsers =
100+
(isSimpleType && (
101+
primType == PrimType.String || lengthKind == LengthKind.Delimited)) ||
100102
(isComplexType && (lengthKind != LengthKind.Implicit && lengthKind != LengthKind.Delimited))
101103

102-
!capturedByParsers && isReferenced
104+
!capturedByValueParsers && isReferenced
103105
}
104106

105107
/**

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/parsers/SpecifiedLengthParsers.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ sealed abstract class SpecifiedLengthParserBase(eParser: Parser, erd: RuntimeDat
8585
if (pState.processorStatus ne Success) return
8686
val finalEndPos0b = startingBitPos0b + nBits
8787

88-
// if we haven't already set the value length, set it now
89-
if (pState.infoset.valueLength.isEndUndef)
88+
// we want to capture the length before we do any skipping
89+
if (pState.infoset.isComplex)
9090
captureValueLength(pState, ULong(startingBitPos0b), ULong(dis.bitPos0b))
9191

9292
Assert.invariant(dis eq pState.dataInputStream)

daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PrefixedTests.tdml

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
-->
1818

1919
<tdml:testSuite suiteName="PrefixedTests"
20-
description="Section 12 - lengthKind=prefixed" xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
21-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
22-
xmlns:xs="http://www.w3.org/2001/XMLSchema"
23-
xmlns:fn="http://www.w3.org/2005/xpath-functions"
24-
xmlns:ex="http://example.com"
25-
xmlns:tns="http://example.com"
26-
xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions"
27-
defaultRoundTrip="onePass" xmlns:x="http://www.ogf.org/dfdl/dfdl-1.0/">
20+
description="Section 12 - lengthKind=prefixed" xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
22+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
23+
xmlns:fn="http://www.w3.org/2005/xpath-functions"
24+
xmlns:ex="http://example.com"
25+
xmlns:tns="http://example.com"
26+
xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions"
27+
defaultRoundTrip="onePass" xmlns:x="http://www.ogf.org/dfdl/dfdl-1.0/">
2828

2929
<tdml:defineSchema name="lengthKindPrefixed-text.dfdl.xsd">
3030

0 commit comments

Comments
 (0)