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 2018/11/01 19:10:57 UTC
[incubator-daffodil] branch master updated: Do not allow ' ' at the
start or end of delimiters
This is an automated email from the ASF dual-hosted git repository.
jadams pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git
The following commit(s) were added to refs/heads/master by this push:
new cf18604 Do not allow ' ' at the start or end of delimiters
cf18604 is described below
commit cf18604bcbbb6dd57f9a1002b25c9968cfc1c4de
Author: Josh Adams <ja...@tresys.com>
AuthorDate: Wed Oct 31 09:00:54 2018 -0400
Do not allow ' ' at the start or end of delimiters
Delimiters with a leading or trailing ' ' now cause an SDE with an error
message suggesting the use of '%SP;' instead.
DAFFODIL-1956
---
.../apache/daffodil/cookers/EntityReplacer.scala | 5 +++
.../delimiter_properties/DelimiterProperties.tdml | 48 ++++++++++++++++++++++
.../sequence_groups/SequenceGroupDelimiters.tdml | 2 +-
.../TestDelimiterProperties.scala | 2 +
4 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala b/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala
index 340c466..baf8049 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/cookers/EntityReplacer.scala
@@ -641,7 +641,12 @@ sealed abstract class ListOfStringLiteralBase(
private lazy val olc = oneLiteralCooker
protected def cook(raw: String, context: ThrowsSDE, forUnparse: Boolean): List[String] = {
+ if (raw.length != 0 && (raw.head.isWhitespace || raw.last.isWhitespace)) {
+ context.SDE("The property '%s' cannot start or end with the string \" \", did you mean to use '%%SP;' instead?", propNameArg)
+ }
+
val rawList = raw.split("\\s+").toList
+
val cooked = {
val cookedList: ListBuffer[String] = ListBuffer.empty
rawList.foreach(x => {
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml
index 368f6bf..281d8b2 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section12/delimiter_properties/DelimiterProperties.tdml
@@ -111,6 +111,24 @@
</xs:complexType>
</xs:element>
+ <xs:element name="DP_04_02" dfdl:lengthKind="implicit">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="s1" type="xs:float"
+ dfdl:terminator=" %WSP+;" maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="DP_04_03" dfdl:lengthKind="implicit">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="s1" type="xs:float"
+ dfdl:terminator="%WSP+; " maxOccurs="unbounded" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
</tdml:defineSchema>
<tdml:defineSchema name="DelimiterProperties-Embedded2.dfdl.xsd">
@@ -316,6 +334,36 @@
</tdml:infoset>
</tdml:parserTestCase>
+ <tdml:parserTestCase name="DelimProp_10_02" root="DP_04_02"
+ model="DelimiterProperties-Embedded.dfdl.xsd"
+ description="Section 12 property delimiters -use of empty space as terminator - DFDL-12-033R Should fail"
+ roundTrip="twoPass">
+
+ <tdml:document><![CDATA[.00300 -02.75
+ 3.9900 7.33
+ ]]></tdml:document>
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>cannot start or end</tdml:error>
+ <tdml:error>use '%SP;' instead</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase name="DelimProp_10_03" root="DP_04_03"
+ model="DelimiterProperties-Embedded.dfdl.xsd"
+ description="Section 12 property delimiters -use of empty space as terminator - DFDL-12-033R Should fail"
+ roundTrip="twoPass">
+
+ <tdml:document><![CDATA[.00300 -02.75
+ 3.9900 7.33
+ ]]></tdml:document>
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ <tdml:error>cannot start or end</tdml:error>
+ <tdml:error>use '%SP;' instead</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
<tdml:parserTestCase name="OptionalWSPTermWithExplicitLength" root="e1"
model="DelimiterProperties-Embedded2.dfdl.xsd"
description="Section 14 Sequence groups with delimiters -use of %WSP*; as terminator - DFDL-12-033R should pass"
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml
index d84a38d..5f553c5 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section14/sequence_groups/SequenceGroupDelimiters.tdml
@@ -444,7 +444,7 @@
<xs:complexType>
<xs:sequence dfdl:separator="">
<xs:element name="quantity" type="xs:int"/>
- <xs:element name="item" type="xs:string" dfdl:initiator="Item: " />
+ <xs:element name="item" type="xs:string" dfdl:initiator="Item:%SP;" />
</xs:sequence>
</xs:complexType>
</xs:element>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section12/delimiter_properties/TestDelimiterProperties.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section12/delimiter_properties/TestDelimiterProperties.scala
index 3cfc9c2..a58635c 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section12/delimiter_properties/TestDelimiterProperties.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section12/delimiter_properties/TestDelimiterProperties.scala
@@ -59,6 +59,8 @@ class TestDelimiterProperties {
@Test def test_DelimProp_10() = { runner_02.runOneTest("DelimProp_10") }
@Test def test_DelimProp_10_01() = { runner_02.runOneTest("DelimProp_10_01") }
+ @Test def test_DelimProp_10_02() = { runner_02.runOneTest("DelimProp_10_02") }
+ @Test def test_DelimProp_10_03() = { runner_02.runOneTest("DelimProp_10_03") }
@Test def test_E1() = { runner_02.runOneTest("E1") }