Problem/Motivation

An <ace> tag without attributes raises a warning every time the text is rendered:

Warning: foreach() argument must be of type array|object, false given in Drupal\ace_editor\Plugin\Filter\AceFilter->process() (line 141 of src/Plugin/Filter/AceFilter.php).
Drupal\ace_editor\Plugin\Filter\AceFilter->process() (Line: 122)
Drupal\filter\Element\ProcessedText::preRenderText()

tagAttributes() returns FALSE when the tag carries no attributes, and process() iterates over that return value without a guard.

A tag with no attributes is the documented basic usage - docs/index.md and docs/1-users/3-filter.md both introduce the filter as <ace> ... </ace> - so the warning appears on the simplest case the module offers. The snippet itself still renders; the attribute loop is skipped, which is correct when there are no attributes, so the effect is a warning on every render rather than broken output.

The existing unit test testNoAttributesReturnsFalse() asserted the FALSE return, so the contract was locked in by a test while no caller could handle it.

Steps to reproduce

  1. Enable the Ace Filter on a text format.
  2. Put a tag with no attributes in a node body: <ace>const value = 1;</ace>
  3. View the node with error reporting set to show warnings.

Reproduced on Drupal 11.4.5, PHP 8.4. tagAttributes('ace', '<ace>code</ace>') returns false, and so does '<ace >code</ace>'.

Proposed resolution

Return an empty array from tagAttributes() when the tag carries no attributes. An accessor with nothing to report returns an empty set, iterating it is a no-op, and an existing if (!$attributes) check keeps behaving the same because an empty array is falsy.

The unit test is updated to assert the empty array, and a kernel test covers processing a bare tag, an attributed tag, both together, and text with no tag, asserting that nothing is raised in each case.

Screenshots

The same node, carrying a tag with no attributes, before and after the fix.

 the same page with no warning and the snippet rendered with line numbers.

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ✅ Automated unit/functional testing coverage
  • ➖ Developer Documentation support
  • ➖ User Guide Documentation support
  • ➖ UX/UI designer responsibilities
  • ➖ Accessibility and Readability
  • ❌ Reviewed by a human
  • ❌ Code review by maintainers
  • ❌ Full testing and approval
  • ❌ Credit contributors
  • ❌ Review with the product owner
  • ❌ Update Release Notes
  • ❌ Release

User interface changes

  • N/A

API changes

  • AceFilter::tagAttributes() returns an empty array instead of FALSE when a tag carries no attributes.

Data model changes

  • N/A

Release notes snippet

  • Fixed a warning raised on every render of an <ace> tag that carries no attributes.
CommentFileSizeAuthor
#5 ace-baretag-comparison.png58.44 KBrajab natshah

Issue fork ace_editor-3618865

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rajab natshah created an issue. See original summary.

rajab natshah’s picture

Issue summary: View changes

  • rajab natshah committed 3b7b1d36 on 2.0.x
    fix: #3618865 Return an empty attribute set for a tag without attributes
    
rajab natshah’s picture

Issue summary: View changes
StatusFileSize
new58.44 KB

Added a before and after screenshot of a bare tag on a node page.

rajab natshah’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rajab natshah’s picture

Issue tags: +ace_editor-2.0.4

✅ Released ace_editor-2.0.4

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.