Problem/Motivation

Steps to reproduce

  1. Environment:
    • Drupal core: 10/11 (specify exact)
    • Views Bootstrap: 5.x (specify exact tag)
    • PHP: 8.1/8.2 (specify exact)
  2. Create a Views Bootstrap: Tabs (or Accordion) display.
  3. Set the tab/heading field (e.g., a title or text field) in the style options.
  4. 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).
  5. 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) returning Xss::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 receiving NULL. Guarding ensures a string is always passed.
  • Stack traces typically originate at views_bootstrap.theme.inc in the Tabs/Accordion preprocessors.
CommentFileSizeAuthor
views_bootstrap-null-xss.patch2.09 KBsbinatl

Comments

sbinatl created an issue. See original summary.

shelane’s picture

Issue summary: View changes
shelane’s picture

Issue summary: View changes