Olabusayo Kilo created DAFFODIL-2943:
----------------------------------------
Summary: LengthKind="prefix" textPadKind="padChar" incorrectly
padding around prefixed length
Key: DAFFODIL-2943
URL: https://issues.apache.org/jira/browse/DAFFODIL-2943
Project: Daffodil
Issue Type: Bug
Components: Back End, Unparsing
Affects Versions: 3.9.0
Reporter: Olabusayo Kilo
If you add the following example in
daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PrefixedTests.tdml,
you get the failure below. This is incorrect because according to the spec,
the length of the prefixed element is the content length which includes the
padding (see excerpt from spec below), so the padding ought to be around the
ABC, and then we ought to calculate the prefix length. This means we shouldn't
suspend padding till the end, and we should pad before we calculate the prefix
length.
We also calculate the prefix length using the value length of the element,
which seems incorrect as well.
{code:xml}
<xs:element name="root9">
<xs:complexType>
<xs:sequence>
<xs:element name="s" dfdl:lengthKind="prefixed"
dfdl:prefixLengthType="ex:prefixType2"
dfdl:textTrimKind="padChar"
dfdl:textPadKind="padChar"
dfdl:textStringPadCharacter="%SP;"
dfdl:textStringJustification="center">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="7"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="e" type="xs:int"
dfdl:inputValueCalc='{ dfdl:valueLength(../s, "bytes") }'>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
{code}
{code:xml}
<tdml:parserTestCase name="pl_simpleValueLengthBytes_3"
model="lengthKindPrefixed-2" roundTrip="onePass">
<tdml:document>
<tdml:documentPart type="byte">00 00 00 0B</tdml:documentPart>
<tdml:documentPart type="text"> ABC </tdml:documentPart>
</tdml:document>
<tdml:infoset>
<tdml:dfdlInfoset>
<ex:root9>
<s>ABC</s>
<e>3</e>
</ex:root9>
</tdml:dfdlInfoset>
</tdml:infoset>
</tdml:parserTestCase>
{code}
{code:java}
org.apache.daffodil.tdml.TDMLExceptionImpl: (Implementation: daffodil) Unparsed
data differs at byte 1. Expected 0x00. Actual was 0x20.
Data (as strings) was
(actual) '␣␣␀␀␀␇ABC␣␣'
(expected) '␀␀␀␋␣␣ABC␣␣'.
{code}
{noformat}
An element of specified length with dfdl:lengthKind 'prefixed' is considered to
have a variable length when unparsing. Specifically, the processor
automatically determines the value to store in the prefix, based on the length
of the SimpleContent or ComplexContent regions, and the properties which modify
the interpretation of the prefix length value, such as
dfdl:prefixIncludesPrefixLength.
{noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)