티스토리 수익 글 보기

티스토리 수익 글 보기

Escape `get_search_query()` in bundled themes by sabernhardt · Pull Request #6685 · WordPress/wordpress-develop · GitHub
Skip to content

Conversation

@sabernhardt
Copy link

@sabernhardt sabernhardt commented May 30, 2024

  • esc_html() in search.php templates
  • esc_attr() in searchform.php templates

Trac 58127


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

github-actions bot commented May 30, 2024

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 sabernhardt, petitphp.

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

@github-actions
Copy link

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.

</span>
</label>
<input type=”search” id=”<?php echo $unique_id; ?>” class=”search-field” placeholder=”<?php echo esc_attr_x( Search &hellip;, placeholder, twentyseventeen ); ?>” value=”<?php echo get_search_query(); ?>” name=”s” />
<input type=”search” id=”<?php echo $unique_id; ?>” class=”search-field” placeholder=”<?php echo esc_attr_x( Search &hellip;, placeholder, twentyseventeen ); ?>” value=”<?php echo esc_attr( get_search_query() ); ?>” name=”s” />
Copy link

@petitphp petitphp May 31, 2024

Choose a reason for hiding this comment

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

I believe we don’t need to add esc_attr in this case. get_search_query() already use esc_attr by default on the return value.

Copy link
Author

Choose a reason for hiding this comment

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

No, that doesn’t seem necessary. I had figured that the authors of about 850 themes knew something I didn’t.

That also makes me question whether esc_html() would add any value, but I will revert the esc_attr() changes for now.

Copy link

Choose a reason for hiding this comment

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

Adding the esc_html() make sens to me.


$archive_title = sprintf(
%1$s %2$s,
%1$s &ldquo;%2$s&rdquo;,
Copy link
Author

Choose a reason for hiding this comment

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

The quotation marks probably should have been translatable.

Suggested change
%1$s &ldquo;%2$s&rdquo;,
/* translators: Main heading for the Search results template. 1: “Search:” text, 2: search query. */
__( %1$s &ldquo;%2$s&rdquo;, twentytwenty ),

@sabernhardt
Copy link
Author

I updated each of the Search template headings to use esc_html without running esc_attr too (including Twenty Sixteen, Twenty Twenty and Twenty Twenty-One).
esc_html( get_search_query( false ) )

@sabernhardt
Copy link
Author

Committed in r61427

@sabernhardt sabernhardt closed this Jan 3, 2026
@sabernhardt sabernhardt deleted the themes-escape-search-query branch January 3, 2026 22:28
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.

2 participants