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

Parser: Fix boolean attribute explicit string value result #7610

Merged
merged 2 commits into from
Jun 28, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Jun 28, 2018

Related: #7322

This pull request seeks to fix an issue in the implementation of #7322 where an explicit string value assigned as an attribute would be wrongly interpreted as false when assigned as a boolean attribute type. Both <input disabled> and <input disabled="disabled"> should return true for a boolean attribute source type.

Testing instructions:

Ensure unit tests pass:

npm run test-unit blocks/api/parser.js

Repeat testing instructions from #7322.

@aduth aduth added [Type] Bug An existing feature does not function as intended [Feature] Block API API that allows to express the block paradigm. [Feature] Parsing Related to efforts to improving the parsing of a string of data and converting it into a different f labels Jun 28, 2018
Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it! A few comments/questions but approach is right on.

@@ -19,6 +19,22 @@ import { isValidBlock } from './validation';
import { getCommentDelimitedContent } from './serializer';
import { attr, prop, html, text, query, node, children } from './matchers';

/**
* Higher-order hpq matcher which enhances an attribute matcher to return true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice docs 👍

*
* @param {Function} matcher Original hpq matcher.
*
* @return {Function} Enhanced hpq matcher.``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the backticks at the end are for 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the backticks at the end are for 🤷‍♂️

Fat fingered 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my guess 😆

*/
export const toBooleanAttributeMatcher = ( matcher ) => flow( [
matcher,
( value ) => value !== undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost asked "what about a false value?" but that should never happen. Not sure if it's worth adding docs just to remind the reader about that.

@@ -132,6 +174,19 @@ describe( 'block parser', () => {
expect( value ).toBe( true );
} );

it( 'should return the matcher\'s true boolean attribute value on explicit attribute value', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a case where I'm like #7366 for the win 😉

@aduth
Copy link
Member Author

aduth commented Jun 28, 2018

Thanks for the review @tofumatt . I pushed a few documentation updates in de1c2ea per your feedback.

@tofumatt
Copy link
Member

Nice, I love the table 👍

@aduth aduth merged commit 9eb1e8f into master Jun 28, 2018
@aduth aduth deleted the fix/parser-boolean-attribute-explicit branch June 28, 2018 16:03
@danielbachhuber danielbachhuber added this to the 3.2 milestone Jun 28, 2018
@danielbachhuber
Copy link
Member

Thanks @aduth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Parsing Related to efforts to improving the parsing of a string of data and converting it into a different f [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants