-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow empty leading/trailing whitespace for list-of-strings properties #1105
Allow empty leading/trailing whitespace for list-of-strings properties #1105
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I did find 2 places where a generic message mentions a specific property, so fix those. But other than those quick fixes this looks good
@@ -774,18 +763,14 @@ class NonEmptyListOfStringLiteral(pn: String, allowByteEntities: Boolean) | |||
|
|||
override def testCooked(cookedList: List[String], context: ThrowsSDE) = { | |||
context.schemaDefinitionUnless( | |||
cookedList.exists { _.length > 0 }, | |||
cookedList.length > 0, | |||
"Property dfdl:%s cannot be empty string. Use dfdl:nilValue='%%ES;' for empty string as nil value.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This messsage mentions dfdl:nilValue but at least in theory it is not the only property that would use this cooker.
Just drop the property name. I think the message is ok without it. Or pass it in as a parameters somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use %s
and propName
so the error message should stay the same so not break existing tests.
Semi-related, in making these changes, I noticed a lot of duplication in our cookers (e.g. these multiple nil cookers). I'm thinking at some point we may want to refactor these. For example, we have some really complicated cookers that are like:
object ChoiceDispatchKeyCooker extends StringLiteralNonEmptyNoCharClassEntitiesNoByteEntities()
I imagine we can replace these just just a bunch of mixins, e.g.
object ChoiceDispatchKeyCooker extends StringLiteral
with NonEmptyLiteral
with NoCharClassEntities
with NoByteEntities
So we just create a bunch of tiny specific traits that are easy to write and verify, and stack them all together. It makes the cooker definitions a bit longer, but makes it much easier to fix/change them without having to create new 50+ character classes when a new property needs something slightly different.
For another day though.
@@ -889,16 +874,16 @@ class NonEmptyListOfStringLiteralCharClass_ES_WithByteEntities(pn: String) | |||
|
|||
override def testCooked(cookedList: List[String], context: ThrowsSDE) = { | |||
context.schemaDefinitionUnless( | |||
cookedList.exists { _.length > 0 }, | |||
cookedList.length > 0, | |||
"Property dfdl:%s cannot be empty string. Use dfdl:nilValue='%%ES;' for empty string as nil value.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue. Hard coded nilValue in message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Minor suggestion to make a test case a bit more intuitive.
...odil-test/src/test/resources/org/apache/daffodil/section23/dfdl_expressions/expressions.tdml
Outdated
Show resolved
Hide resolved
Currently we SDE if a property that accepts of list of DFDL string literals starts or end with whitespace. This removes that restriction in the list cooker by splitting on whitespace and removing any strings that are the empty string. This has one side effect that the resulting list can now be empty--previously an empty property would have a single element with the empty string. An empty list is easier to reason about and detect than a list with a single zero-length string, but it does require changing the logic in a few places. DAFFODIL-2858
e3573c8
to
eedb76b
Compare
Currently we SDE if a property that accepts of list of DFDL string literals starts or end with whitespace. This removes that restriction in the list cooker by splitting on whitespace and removing any strings that are the empty string.
This has one side effect that the resulting list can now be empty--previously an empty property would have a single element with the empty string. An empty list is easier to reason about and detect than a list with a single zero-length string, but it does require changing the logic in a few places.
DAFFODIL-2858