WordPress.org

Make WordPress Core

Ticket #29882: 29882_embed.diff

File 29882_embed.diff, 2.7 KB (added by gitlost, 4 years ago)

Extra pass for embedded quotes.

  • src/wp-includes/formatting.php

     
    4444                $static_replacements = null,
    4545                $dynamic_characters = null,
    4646                $dynamic_replacements = null,
     47                $dynamic_characters_embed = null,
     48                $dynamic_replacements_embed = null,
    4749                $default_no_texturize_tags = null,
    4850                $default_no_texturize_shortcodes = null,
    4951                $run_texturize = true,
     
    137139                $dynamic = array();
    138140                $spaces = wp_spaces_regexp();
    139141
     142                // Embedded quotes "'Hello' he said" she said.
     143                if ( "'" !== $opening_single_quote || "'" !== $closing_single_quote || '"' !== $opening_quote || '"' !== $closing_quote ) {
     144                        $dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')\'"/' ] = $open_sq_flag . $open_q_flag;
     145                        $dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')"\'/' ] = $open_q_flag . $open_sq_flag;
     146                        $dynamic[ '/\'"(?=\z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote . $closing_quote;
     147                        $dynamic[ '/"\'(?=\z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_quote . $closing_single_quote;
     148
     149                        $dynamic_characters_embed = array_keys( $dynamic );
     150                        $dynamic_replacements_embed = array_values( $dynamic );
     151                        $dynamic = array();
     152                }
     153
    140154                // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
    141155                if ( "'" !== $apos || "'" !== $closing_single_quote ) {
    142156                        $dynamic[ '/\'(\d\d)\'(?=\Z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_single_quote;
     
    288302
    289303                        $curl = str_replace( $static_characters, $static_replacements, $curl );
    290304
     305                        $have_q = false !== strpos( $curl, '"' ); // Need to check for double quotes beforehand in case they're turned into flags by $dynamic_characters_embed.
    291306                        if ( false !== strpos( $curl, "'" ) ) {
     307                                if ( $dynamic_characters_embed && $have_q && ( false !== strpos( $curl, '\'"' ) || false !== strpos( $curl, '"\'' ) ) ) {
     308                                        $curl = preg_replace( $dynamic_characters_embed, $dynamic_replacements_embed, $curl );
     309                                }
    292310                                $curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl );
    293311                                $curl = wptexturize_primes( $curl, "'", $prime, $open_sq_flag, $closing_single_quote );
    294312                                $curl = str_replace( $apos_flag, $apos, $curl );
    295313                                $curl = str_replace( $open_sq_flag, $opening_single_quote, $curl );
    296314                        }
    297                         if ( false !== strpos( $curl, '"' ) ) {
     315                        if ( $have_q ) {
    298316                                $curl = preg_replace( $dynamic_characters['quote'], $dynamic_replacements['quote'], $curl );
    299317                                $curl = wptexturize_primes( $curl, '"', $double_prime, $open_q_flag, $closing_quote );
    300318                                $curl = str_replace( $open_q_flag, $opening_quote, $curl );