#56007 closed defect (bug) (fixed)
Correct the escaping in documentation lookup for plugin and theme editor
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.1 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Administration | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
There is some similar code for documentation lookup in plugin and theme code editors.
wp-admin/plugin-editor.php:
if ( '.php' === substr( $real_file, strrpos( $real_file, '.' ) ) ) {
$functions = wp_doc_link_parse( $content );
if ( ! empty( $functions ) ) {
$docs_select = '<select name="docs-list" id="docs-list">';
$docs_select .= '<option value="">' . __( 'Function Name…' ) . '</option>';
foreach ( $functions as $function ) {
$docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>';
}
$docs_select .= '</select>';
}
}
wp-admin/theme-editor.php:
if ( '.php' === substr( $file, strrpos( $file, '.' ) ) ) {
$functions = wp_doc_link_parse( $content );
$docs_select = '<select name="docs-list" id="docs-list">';
$docs_select .= '<option value="">' . esc_attr__( 'Function Name…' ) . '</option>';
foreach ( $functions as $function ) {
$docs_select .= '<option value="' . esc_attr( urlencode( $function ) ) . '">' . htmlspecialchars( $function ) . '()</option>';
}
$docs_select .= '</select>';
}
How many differences can you find? :) Over the years, both of these fragments evolved in slightly different ways:
- [10607] / #9184 introduced documentation lookup shortcuts both for the plugin and theme editor.
- [10879] / #9452 replaced
urlencode()withattribute_escape(), lateresc_attr(), in the plugin editor. - [11110] / #9650 added
_a(), lateresc_attr__(), for "Function Name..." in the theme editor. - [11173] added attribute escaping for
$functionin the theme editor, without removingurlencode(). - [11204] / #9650 replaced
attr()withesc_attr()and_a()withesc_attr__(). - [11671] / #10262 added a
! empty( $functions )check for the plugin editor. - [14989] replaced
htmlspecialchars()withesc_html()in the plugin editor.
The attached patch brings some consistency:
- The
! empty( $functions )check only existed in the plugin editor, it should be added to the theme editor too. - "Function Name..." is an option label, not an attribute, so
esc_html__()would be the correct function here. esc_attr( urlencode( $function ) )in the theme editor is redundant, justesc_attr()is enough there.htmlspecialchars( $function )in the theme editor can be replaced withesc_html( $function ).
Noticed and patched in a working session on #53465 with @aristath, @justinahinon, @poena, and @SergeyBiryukov.
Attachments (1)
Change History (6)
This ticket was mentioned in PR #2998 on WordPress/wordpress-develop by pratiweb.
4 years ago
#2
Created pull request with correction needed in core for escaping
Trac ticket: https://core.trac.wordpress.org/ticket/56007
#3
@
4 years ago
@pratiweb I can't see any difference between your PR and the previous patch (56007.diff, proposed 5 weeks ago in this ticket)?
(also it looks like your PR has several coding standards issues)
#4
@
4 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 53758:
SergeyBiryukov commented on PR #2998:
4 years ago
#5
Thanks for the PR! Merged in r53758.
Looks good to me! Thank you for addressing these inconsistencies @SergeyBiryukov.
Marking for commit.