Making WordPress.org

Changeset 10190


Ignore:
Timestamp:
08/19/2020 10:24:15 PM (4 years ago)
Author:
coffee2code
Message:

Developer, Code Standards Handbook: Fix (as a stopgap) double-encoding of HTML entities.

SyntaxHighligher Evolved's handling of HTML entities in code shortcodes is the likely culprit. Use of triple backticks in the source Markdown files to denote code blocks (as done in the Block Editor Handbook) could circumvent the issue.

Props kmarcink, coffee2code.
Fixes #5346.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/import-coding-standards.php

    r8686 r10190  
    1313
    1414        add_filter( 'handbook_label', array( $this, 'change_handbook_label' ), 10, 2 );
     15        add_filter( 'the_content', array( $this, 'fix_double_encoding' ) );
    1516    }
    1617
     
    3132        return $label;
    3233    }
     34
     35    /**
     36     * Fixes (as a stopgap) encoding of already encoded characters in code shortcodes.
     37     *
     38     * Affected characters:
     39     * - '&` (sometimes)
     40     * - `<`
     41     * - `*` (when encoded in the first place)
     42     * - `?` (when encoded in the first place)
     43     * - `"` (in some places when used as opening quote)
     44     *
     45     * This could probably be abrogated by the source using triple backticks to
     46     * denote code.
     47     *
     48     * @see https://meta.trac.wordpress.org/ticket/5346
     49     *
     50     * @param string $content Post content.
     51     * @return string
     52     */
     53    public function fix_double_encoding( $content ) {
     54        if ( $this->get_post_type() === get_post_type() ) {
     55            $content = str_replace(
     56                [ '&amp;amp;', '&amp;042;', '&amp;#042;', '&amp;lt;', '&amp;quest;', '&amp;quot;' ],
     57                [ '&amp;', '&#042;', '&#042;', '&lt;', '&quest;', '&quot;' ],
     58                $content
     59            );
     60        }
     61        return $content;
     62    }
    3363}
    3464
Note: See TracChangeset for help on using the changeset viewer.