Skip to content

Conversation

@thomasnavarro
Copy link
Contributor

Summary

Fixes #29

This PR fixes a bug where the tabs block crashes when a tab title contains special characters (e.g., apostrophe ', quotes ", etc.).

Problem

The data-wp-context attribute in src/tabs/render. php was not properly escaping the JSON output:

data-wp-context='<?php echo wp_json_encode($data_context); ?>'

When a tab title like L'onglet was used, the generated HTML would break:

data-wp-context='{"tabs":[{"label":"L'onglet"... }]}'

The apostrophe in the title prematurely closes the HTML attribute, causing the block to crash.

Solution

Wrap wp_json_encode() with esc_attr() to properly escape special characters:

data-wp-context='<?php echo esc_attr(wp_json_encode($data_context)); ?>'

This ensures that special characters are encoded as HTML entities ('&#039;) in the attribute, while the browser automatically decodes them when parsing, so the title displays correctly on screen.

Testing

  1. Create a tabs block in the editor
  2. Set a tab title with special characters (e.g., It's working! or Test "quotes")
  3. Save and view the page on the frontend
  4. ✅ The block should render correctly without crashing
  5. ✅ The tab title should display the special characters properly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

Copy link
Contributor

@Verma-Punit Verma-Punit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🫶🏻

@Verma-Punit Verma-Punit merged commit 0bb7559 into lubusIN:main Dec 5, 2025
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.

(bug-tabs): block crashes when there is a special character in the tab title

3 participants