You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2020/08/27 14:46:24 UTC
[GitHub] [incubator-daffodil] stevedlawrence commented on a change in pull request #409: Addressed Daffodil-2122 default="0|1" causes exception for xs:boolean…
stevedlawrence commented on a change in pull request #409:
URL: https://github.com/apache/incubator-daffodil/pull/409#discussion_r478455328
##########
File path: daffodil-test/src/test/resources/org/apache/daffodil/section13/boolean/boolean.tdml
##########
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (c) 2019 Tresys Technology, LLC. All rights reserved. -->
Review comment:
We cannot accept code that is not licensing under Apache License v2, or something compatible. Code contributed to the project should ideally have the following license header:
```xml
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
```
Please see other tdml files for examples of this.
##########
File path: daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/NodeInfo.scala
##########
@@ -699,7 +699,14 @@ object NodeInfo extends Enum {
protected sealed trait BooleanKind extends AnySimpleType.Kind
case object Boolean extends PrimTypeNode(AnyAtomic) with BooleanKind with PrimNonNumeric with BooleanView {
type Kind = BooleanKind
- protected override def fromString(s: String): DataValueBool = s.toBoolean
+ protected override def fromString(s: String): DataValueBool = {
+ // Note: Any boolean default value other than true, false, 1, or 0
+ // will throw a SDE resulting from a SAXParseException
+ s match {
+ case "0" | "false" => false
+ case "1" | "true" => true
+ }
Review comment:
Actually ``fromXMLString`` and thus ``fromString`` are used in many places other that defaulting, so that comment isn't always going to be accurate. And in some of those cases, we can't rely on schema validation/SAX errors. For example, you could have a schema like this:
```xml
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="str" type="xs:string" ... />
<xs:element name="bool" type="xs:boolean" dfdl:inputValueCalc="{ xs:boolean(../str) }" />
</xs:string>
</xs:complexType>
</xs:element>
```
In this case, the conversion of str to an xs:boolean will use this fromString function and isn't validated by SAX. In that case, we robably would get a scala MatchError, which wouldn't be good for diagnostics.
So I would suggest removing that comment and having a default case that's something like:
```scala
case _ => throws an IllegalArgumentException("Must be one of 0, 1, true, or false")
```
Then ``fromXMLString`` will catch that and create the appropriate error when it does occur.
If we don't have a test like the above, it might also be worth adding to make sure inputCalueCalc runtime conversions give an appropriate error.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org