Skip to content

Fix: Prevent empty markup when site title or description is empty#8582

Closed
Sukhendu2002 wants to merge 10 commits intoWordPress:trunkfrom
Sukhendu2002:fix/empty-site-title-markup
Closed

Fix: Prevent empty markup when site title or description is empty#8582
Sukhendu2002 wants to merge 10 commits intoWordPress:trunkfrom
Sukhendu2002:fix/empty-site-title-markup

Conversation

@Sukhendu2002
Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/44656


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@Sukhendu2002 Sukhendu2002 marked this pull request as ready for review March 25, 2025 11:51
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 25, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sukhendu2002, sirlouen, joedolson, sabernhardt.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown
Member

@SirLouen SirLouen left a comment

Choose a reason for hiding this comment

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

I understand that you were taking the @audrasjb first proposal, which is not wrong at all, but can be a little improved.
And after reviewing all my proposed changes, someone could say:

But not empty is a safer choice than full

And its true, but let's not forget that the incoming variables are variables coming from the database, variables that have been sanitized to death. It's not like a first variable coming from a mixed input parameter that we should take extra caution.

Comment thread src/wp-content/themes/twentytwenty/inc/template-tags.php Outdated
Comment thread src/wp-content/themes/twentyten/header.php Outdated
Comment thread src/wp-content/themes/twentyeleven/header.php Outdated
Comment thread src/wp-content/themes/twentyfifteen/header.php Outdated
Comment thread src/wp-content/themes/twentyfifteen/header.php
Comment thread src/wp-content/themes/twentyfourteen/header.php Outdated
Comment thread src/wp-content/themes/twentyseventeen/template-parts/header/site-branding.php Outdated
Comment thread src/wp-content/themes/twentysixteen/header.php Outdated
Comment thread src/wp-content/themes/twentythirteen/header.php Outdated
Comment thread src/wp-content/themes/twentytwelve/header.php Outdated
@Sukhendu2002 Sukhendu2002 requested a review from SirLouen May 23, 2025 12:46
Copy link
Copy Markdown
Member

@SirLouen SirLouen left a comment

Choose a reason for hiding this comment

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

Some additional changes provided in almost all files to improve final code quality, give it a check.

Comment thread src/wp-content/themes/twentyeleven/header.php Outdated
Comment thread src/wp-content/themes/twentyfifteen/header.php
Comment thread src/wp-content/themes/twentyfourteen/header.php Outdated
Comment thread src/wp-content/themes/twentyseventeen/template-parts/header/site-branding.php Outdated
Comment thread src/wp-content/themes/twentysixteen/header.php Outdated
Comment thread src/wp-content/themes/twentyten/header.php
Comment thread src/wp-content/themes/twentythirteen/header.php Outdated
Comment thread src/wp-content/themes/twentytwelve/header.php Outdated
Copy link
Copy Markdown
Contributor

@joedolson joedolson left a comment

Choose a reason for hiding this comment

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

As is, this patch introduces security vulnerabilities. bloginfo() internally calls get_bloginfo() with the filter argument set to display, which executes esc_html on the output. But if you call get_bloginfo() directly, the output is fetched raw, and is not safe.

You can either add the display argument to all get_bloginfo() calls or add late escaping to the resulting variables; either would fix the issue.

Comment thread src/wp-content/themes/twentyeleven/header.php Outdated
Comment thread src/wp-content/themes/twentyeleven/header.php Outdated
Comment thread src/wp-content/themes/twentyfifteen/header.php Outdated
Comment thread src/wp-content/themes/twentyfourteen/header.php Outdated
Comment thread src/wp-content/themes/twentyseventeen/template-parts/header/site-branding.php Outdated
Comment thread src/wp-content/themes/twentyten/header.php Outdated
Comment thread src/wp-content/themes/twentythirteen/header.php Outdated
Comment thread src/wp-content/themes/twentythirteen/header.php Outdated
Comment thread src/wp-content/themes/twentytwelve/header.php Outdated
Comment thread src/wp-content/themes/twentytwelve/header.php Outdated
@sabernhardt
Copy link
Copy Markdown

The display filter in bloginfo() ran the name and description through wptexturize and convert_chars in addition to esc_html.

In the event that filtering might empty the string, adding display in the variable could help:

$site_name        = get_bloginfo( 'name', 'display' );
$site_description = get_bloginfo( 'description', 'display' );

PHPCS might complain about <?php echo $site_name; ?>, but the PR passes the coding standards GitHub action. I would prefer not to add the phpcs:ignore comments.

@Sukhendu2002 Sukhendu2002 requested a review from joedolson June 2, 2025 07:30
@github-actions
Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 60483
GitHub commit: d71b1d8

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 18, 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.

4 participants