Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid escaping text incorrectly. #2882

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelogs/fix-form-field-selected-escaping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
significance: patch
type: fixed
entry: Avoid escaping the selected attribute of a form field select dropdown
incorrectly.
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ class="<?php echo esc_attr( $this->field['class'] ); ?>"

<?php
foreach ( $this->field['value'] as $key => $option ) :
$selected_text = '';
$is_selected = false;
if ( is_array( $selected ) ) {
if ( in_array( $option['key'], $selected ) ) {
$selected_text = ' selected="selected" ';
$is_selected = true;
}
} elseif ( isset( $option['key'] ) && $option['key'] == $selected ) {
$selected_text = ' selected="selected" ';
$is_selected = true;
} elseif ( $key === $selected ) {
$selected_text = ' selected="selected" ';
$is_selected = true;
}
?>
<option value="<?php echo isset( $option['key'] ) ? esc_attr( $option['key'] ) : esc_attr( $key ); ?>"<?php echo esc_html( $selected_text ); ?>><?php echo isset( $option['title'] ) ? esc_html( $option['title'] ) : esc_html( $option ); ?></option>
<option value="<?php echo isset( $option['key'] ) ? esc_attr( $option['key'] ) : esc_attr( $key ); ?>"<?php echo ( $is_selected ? ' selected="selected"' : '' ); ?>><?php echo isset( $option['title'] ) ? esc_html( $option['title'] ) : esc_html( $option ); ?></option>

<?php endforeach; ?>

Expand Down
Loading