Skip to content

Commit

Permalink
Properly parsing "true"/"false" values in a boolean HTML attribute. See
Browse files Browse the repository at this point in the history
  • Loading branch information
David Aguilera committed Feb 20, 2019
1 parent 4124d92 commit 084fc8a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/blocks/src/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ const STRING_SOURCES = new Set( [

/**
* Higher-order hpq matcher which enhances an attribute matcher to return true
* or false depending on whether the original matcher returns undefined. This
* is useful for boolean attributes (e.g. disabled) whose attribute values may
* be technically falsey (empty string), though their mere presence should be
* enough to infer as true.
* or false depending on whether the original matcher returns undefined or the
* "false" string. This is useful for boolean attributes (e.g. disabled) whose
* attribute values may be technically falsey (empty string), though their
* mere presence should be enough to infer as true. It's also useful for those
* boolean attributes whose value is either "true" or "false".
*
* @param {Function} matcher Original hpq matcher.
*
Expand All @@ -63,7 +64,7 @@ export const toBooleanAttributeMatcher = ( matcher ) => flow( [
// <input disabled="disabled">
// - Value: `'disabled'`
// - Transformed: `true`
( value ) => value !== undefined,
( value ) => value !== undefined && value !== 'false',
] );

/**
Expand Down

0 comments on commit 084fc8a

Please sign in to comment.