Skip to content
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

Conversation

stevedlawrence
Copy link
Member

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

Copy link
Contributor

@mbeckerle mbeckerle left a 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.",
Copy link
Contributor

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.

Copy link
Member Author

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.",
Copy link
Contributor

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.

Copy link
Contributor

@bsloane1650 bsloane1650 left a 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.

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
@stevedlawrence stevedlawrence force-pushed the daffodil-2858-leading-trailing-whitespace-list-of-string branch from e3573c8 to eedb76b Compare October 31, 2023 13:16
@stevedlawrence stevedlawrence merged commit b5d0ec7 into apache:main Oct 31, 2023
10 checks passed
@stevedlawrence stevedlawrence deleted the daffodil-2858-leading-trailing-whitespace-list-of-string branch October 31, 2023 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants