fix(helpers): keep falsy but defined values in fillTemplate - #12609
Open
Arunendra21 wants to merge 1 commit into
Open
fix(helpers): keep falsy but defined values in fillTemplate#12609Arunendra21 wants to merge 1 commit into
Arunendra21 wants to merge 1 commit into
Conversation
fillTemplate replaced each ${var} with `templateVars[match] || ''`,
which also dropped values that are defined but falsy, such as the
number 0 or the boolean false. For example fillTemplate('${n}', {n: 0})
returned an empty string instead of '0'.
This is noticeable in Pagination, where PaginationOptionsMenu passes
numeric firstIndex, lastIndex and itemCount into a string toggle
template. With an empty data set (itemCount of 0) the '0' was silently
dropped from the toggle text.
Use the nullish coalescing operator so only null or undefined values
(for example a missing key) fall back to an empty string, while 0 and
false are kept.
Co-authored-by: eeshsaxena <eeshsaxena@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Walkthrough
ChangesfillTemplate behavior
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
What: Fixes a bug in the
fillTemplatehelper (packages/react-core/src/helpers/util.ts).fillTemplatereplaced each${var}withtemplateVars[match] || '', which also dropped values that are defined but falsy, such as the number0or the booleanfalse. For example:This shows up in Pagination.
PaginationOptionsMenupasses numericfirstIndex,lastIndexanditemCountinto a string toggle template, so an empty data set (itemCountof0) silently dropped the0from the rendered toggle text (for example1 - 0 ofinstead of1 - 0 of 0).The fix switches
||to the nullish coalescing operator??, so onlynullorundefined(for example a missing key) fall back to an empty string, while0andfalseare preserved. Missing keys still resolve to an empty string, so existing behavior is unchanged.Additional issues: none. This was found while reading the helper code.
Testing: added unit tests in
util.test.tscovering0,false, empty string, and missing keys. The existingfillTemplateinterpolation test still passes.Summary by CodeRabbit
Bug Fixes
0,false, and empty strings.Tests