stevedlawrence closed pull request #112: Fix logic related to
lengthKind="pattern" matching
URL: https://github.com/apache/incubator-daffodil/pull/112
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/daffodil-io/src/main/scala/org/apache/daffodil/io/InputSourceDataInputStream.scala
b/daffodil-io/src/main/scala/org/apache/daffodil/io/InputSourceDataInputStream.scala
index cc541b8e9..30f47d2fb 100644
---
a/daffodil-io/src/main/scala/org/apache/daffodil/io/InputSourceDataInputStream.scala
+++
b/daffodil-io/src/main/scala/org/apache/daffodil/io/InputSourceDataInputStream.scala
@@ -571,7 +571,8 @@ final class InputSourceDataInputStream private (val
inputSource: InputSource)
regexMatchBitPositionBuffer.limit(regexMatchBufferLimit)
val numDecoded = finfo.decoder.decode(this, finfo, regexMatchBuffer,
regexMatchBitPositionBuffer)
- val filledToLimit = regexMatchBuffer.position == regexMatchBuffer.limit
+ val potentiallyMoreData = regexMatchBuffer.position ==
regexMatchBuffer.limit
+
regexMatchBuffer.flip
regexMatchBitPositionBuffer.flip
@@ -583,13 +584,13 @@ final class InputSourceDataInputStream private (val
inputSource: InputSource)
val hitEnd = matcher.hitEnd
val requireEnd = matcher.requireEnd
- if (filledToLimit && ((isMatch && requireEnd) || (!isMatch &&
hitEnd))) {
- // We filled the CharBuffer to its limit, so it's possible there
- // is more data available. AND either 1) we got a match but more
- // data could negate it or 2) we hit the end without getting a
- // match but more data might result in a match. In either case,
- // let's increase the match limit if possible, try to decode more
- // data, and try the match again if we got more data.
+ if (potentiallyMoreData && (hitEnd || (isMatch && requireEnd))) {
+ // We filled the CharBuffer to its limit, so it's possible there is
+ // more data available AND either 1) we hit the end of the char
+ // buffer and more data might change the match or 2) we got a match
+ // but require the end and more data could negate the match. In
+ // either case, let's increase the match limit if possible, try to
+ // decode more data, and try the match again if we got more data.
if (regexMatchBufferLimit == regexMatchBuffer.capacity) {
// consumed too much data, just give up
keepMatching = false
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PatternTests.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PatternTests.tdml
index 631b2f5cc..5992fbfda 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PatternTests.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/PatternTests.tdml
@@ -956,4 +956,48 @@
</tdml:parserTestCase>
+
+ <tdml:defineSchema name="lengthPatternBinary">
+ <dfdl:format ref="ex:GeneralFormat" representation="binary" />
+
+ <xs:element name="bin1">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="bin" type="xs:hexBinary" maxOccurs="unbounded"
dfdl:occursCountKind="implicit"
+ dfdl:lengthKind="pattern" dfdl:lengthPattern="[\x00-\xFF]{0,80}"
dfdl:encoding="ISO-8859-1">
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:assert>{ dfdl:valueLength(., 'bytes') gt 0
}</dfdl:assert>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase name="lengthPatternBinaryPatternLimit"
+ root="bin1" model="lengthPatternBinary" description="Section 12
lengthKind-pattern - DFDL-12-087R" >
+
+ <tdml:document>
+ <tdml:documentPart
type="byte">6162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970</tdml:documentPart>
+ <tdml:documentPart
type="byte">6162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970</tdml:documentPart>
+ <tdml:documentPart
type="byte">6162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970</tdml:documentPart>
+ <tdml:documentPart
type="byte">6162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970</tdml:documentPart>
+ </tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <bin1>
+
<bin>6162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970</bin>
+
<bin>6162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970616263646566676869706162636465666768697061626364656667686970</bin>
+
<bin>61626364656667686970616263646566676869706162636465666768697061626364656667686970</bin>
+ </bin1>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+
+ </tdml:parserTestCase>
+
+
+
</tdml:testSuite>
diff --git
a/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPattern.scala
b/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPattern.scala
index 4de8df8f0..7a536c406 100644
---
a/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPattern.scala
+++
b/daffodil-test/src/test/scala/org/apache/daffodil/section12/lengthKind/TestLengthKindPattern.scala
@@ -80,4 +80,6 @@ class TestLengthKindPattern {
@Test def test_hexBinaryLengthKindPattern01() {
runner.runOneTest("hexBinaryLengthKindPattern01") }
@Test def test_lengthPatternEncodingErrorReplace() {
runner.runOneTest("lengthPatternEncodingErrorReplace") }
+
+ @Test def test_lengthPatternBinaryPatternLimit() {
runner.runOneTest("lengthPatternBinaryPatternLimit") }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services