Parser: Support multiple attribute type, reject invalid#10338
Merged
Conversation
packages/blocks/src/api/parser.js
Outdated
|
|
||
| return ( | ||
| isStringSource( source ) && | ||
| typeof type === 'string' |
Member
There was a problem hiding this comment.
Should we check if type === 'string' and not typeof type === 'string'?
Member
Author
There was a problem hiding this comment.
No, because this is how we differentiate between single and multiple types. I can extract a variable to make this clearer.
It's unclear for which string sources should be considered ambiguous and allow casting, in addition to being inconsistently enforced. Rather than defaulting to leniency, we should enforce the type broadly, reintroducing leniency later if noted issues and need for multiple type support can be reconciled.
4 tasks
Closed
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blocker for: #9634
This pull request seeks to enhance the block parser to support multiple
type, in accordance with JSON schema. This is planned to be used in #9634 to support a nullable string foralignattribute, representable in JSON schema as multiple type[ "string", "null" ].In doing so, it needs to account for how to handle existing behavior of attribute value casting, necessary for attributes sourced ambiguously as strings (e.g. as HTML attribute values). With these changes, casting only occurs for ambiguous string sources of a singular attribute type. For any other attribute, we now reject the attribute value (adopting behavior as if
undefined, accounting for default value). This may be considered a breaking change, but only in cases where values were assigned of the wrong type, relying on casting to correct. More often, this should help capture unintended serialization (e.g. objects serialized as casted string[object Object]).Testing instructions:
Verify unit tests pass.