Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
291 stars 206 forks source link

Biographical Info field on contributors profile is double-encoded #352

Open paulschreiber opened 8 years ago

paulschreiber commented 8 years ago

The Biographical Info (cap-description) field is double encoded. It generates HTML like this:

<label for="cap-description">Biographical Info</label></th><td>
<textarea style="width:300px;margin-bottom:6px;" name="cap-description">&amp;amp;Aaron is
here.</textarea>

In class-coauthors-guest-authors.php, in get_guest_author_fields(), we have this code:

array(
        'key'      => 'description',
        'label'    => __( 'Biographical Info', 'co-authors-plus' ),
        'group'    => 'about',
        'sanitize_function' => 'wp_filter_post_kses',
    ),

By calling wp_filter_post_kses instead of the default filter (sanitize_text_field), we end up with the double encoding.

paulschreiber commented 8 years ago

Here's a workaround:

foreach ( $fields as $index => $field ) {
    if ( 'description' === $field['key'] ) {
        $fields[ $index ]['sanitize_function'] = function( $s ) { return html_entity_decode( wp_filter_post_kses( $s ) ); };
    }
}```
philipjohn commented 7 years ago

Could you clarify where you're seeing this please? I'm assuming it's on the guest author edit screen in the "Biographical Info" textarea. Here are the steps I've taken to reproduce:

  1. Create a new guest author
  2. Include this in the "Biographical Info" field: Aaron is here.
  3. Save the author
  4. Check the textarea
  5. Value is Aaron is here. as expected
paulschreiber commented 6 years ago

You missed the the ampersand in step 2. &Aaron is here.

This results in &amp;amp;Aaron is here instead of the expected &amp;Aaron is here.

philipjohn commented 6 years ago

Ah that may have been a typo.

Here's what I'm typing in:

pre-save

Then I hit save and see

post-save

^ That's actually after saving twice (once to add the .).

paulschreiber commented 6 years ago

Yup. That's the bug.

philipjohn commented 6 years ago

This results in &amp;amp;Aaron is here instead of the expected &amp;Aaron is here.

I thought the bug was the double amp as in that ^ example?

paulschreiber commented 6 years ago

My original example showed the HTML source of a double-encoded ampersand (&amp;amp;). Your example showed the rendered version (&amp;). We're seeing the same bug.