Problem/Motivation
Steps to reproduce
- Environment:
- Drupal core: 10/11 (specify exact)
- Views Bootstrap: 5.x (specify exact tag)
- PHP: 8.1/8.2 (specify exact)
- Create a Views Bootstrap: Tabs (or Accordion) display.
- Set the tab/heading field (e.g., a title or text field) in the style options.
- Ensure at least one row has a NULL (not just empty string) value for that field (e.g., field is excluded or not present for that row).
- Render the view (any page/block/embedded display).
Actual result: PHP 8.1+ deprecation notices, e.g.:
Deprecated: Passing null to str_replace()/strlen() in Xss::filter() → Unicode::validateUtf8()
Expected result: No deprecations; NULL values handled safely.
Proposed resolution
- Coalesce/cast values to string before calling
Xss::filter()in preprocessors that read view fields used as labels/titles (Tabs/Accordion). - Add a small helper (example):
views_bootstrap_safe_markup($value, $allowed)returningXss::filter((string) ($value ?? ''), $allowed). - Replace direct
Xss::filter($value, ...)calls with the helper in:template_preprocess_views_bootstrap_tab()template_preprocess_views_bootstrap_accordion()
Remaining tasks
- Code review.
- (Optional) Add a kernel/unit test rendering a Tabs display where the tab field returns
NULL, asserting no deprecations. - Confirm fix on PHP 8.1/8.2 with Views rows containing NULL titles.
- Backport/forward-port as appropriate for supported branches.
- Update change record if required.
User interface changes
None.
API changes
None (adds an internal helper; does not change public APIs).
Data model changes
None.
Additional information
- Root cause:
Xss::filter()ultimately calls string functions that, on PHP 8.1+, deprecate receivingNULL. Guarding ensures a string is always passed. - Stack traces typically originate at
views_bootstrap.theme.incin the Tabs/Accordion preprocessors.
| Comment | File | Size | Author |
|---|---|---|---|
| views_bootstrap-null-xss.patch | 2.09 KB | sbinatl |
Comments
Comment #2
shelaneComment #3
shelane