Skip to content

fix(helpers): keep falsy but defined values in fillTemplate - #12609

Open
Arunendra21 wants to merge 1 commit into
patternfly:mainfrom
Arunendra21:fix-filltemplate-falsy-values
Open

fix(helpers): keep falsy but defined values in fillTemplate#12609
Arunendra21 wants to merge 1 commit into
patternfly:mainfrom
Arunendra21:fix-filltemplate-falsy-values

Conversation

@Arunendra21

@Arunendra21 Arunendra21 commented Aug 3, 2026

Copy link
Copy Markdown

What: Fixes a bug in the fillTemplate helper (packages/react-core/src/helpers/util.ts).

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 '' instead of '0'
fillTemplate('${v}', { v: false }); // returned '' instead of 'false'

This shows up in Pagination. PaginationOptionsMenu passes numeric firstIndex, lastIndex and itemCount into a string toggle template, so an empty data set (itemCount of 0) silently dropped the 0 from the rendered toggle text (for example 1 - 0 of instead of 1 - 0 of 0).

The fix switches || to the nullish coalescing operator ??, so only null or undefined (for example a missing key) fall back to an empty string, while 0 and false are 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.ts covering 0, false, empty string, and missing keys. The existing fillTemplate interpolation test still passes.

Summary by CodeRabbit

  • Bug Fixes

    • Template filling now correctly preserves valid falsy values such as 0, false, and empty strings.
    • Missing or null template values continue to be replaced with empty strings.
  • Tests

    • Added coverage for falsy and missing template values.

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>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 272119af-a0ee-44b1-a537-b3164e418328

📥 Commits

Reviewing files that changed from the base of the PR and between 4e13e7c and e5fc370.

📒 Files selected for processing (2)
  • packages/react-core/src/helpers/__tests__/util.test.ts
  • packages/react-core/src/helpers/util.ts

Walkthrough

fillTemplate now preserves defined falsy values and replaces only null or undefined template values with empty strings. Tests cover these cases.

Changes

fillTemplate behavior

Layer / File(s) Summary
Nullish fallback and coverage
packages/react-core/src/helpers/util.ts, packages/react-core/src/helpers/__tests__/util.test.ts
fillTemplate uses ?? '' to preserve 0, false, and empty strings. Tests cover defined falsy values and missing keys.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preserving defined falsy values in fillTemplate.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant