From 7b41adf712d88ea2a8d5da281940c4c44db2bf88 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 22 Jul 2015 05:14:50 +0000 Subject: [PATCH] Shortcodes: Improve the reliablity of shortcodes inside HTML tags. Props miqrogroove. See #15694. git-svn-id: https://develop.svn.wordpress.org/trunk@33359 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-embed.php | 6 +- src/wp-includes/formatting.php | 71 ++++++++ src/wp-includes/kses.php | 270 ++++++++++++++++++++++++----- src/wp-includes/shortcodes.php | 166 +++++++++++++++++- tests/phpunit/tests/kses.php | 178 +++++++++++++++++++ tests/phpunit/tests/shortcode.php | 76 ++++++++ 6 files changed, 722 insertions(+), 45 deletions(-) diff --git a/src/wp-includes/class-wp-embed.php b/src/wp-includes/class-wp-embed.php index 6bb7217402..148c5f4bf7 100644 --- a/src/wp-includes/class-wp-embed.php +++ b/src/wp-includes/class-wp-embed.php @@ -59,7 +59,7 @@ class WP_Embed { add_shortcode( 'embed', array( $this, 'shortcode' ) ); // Do the shortcode (only the [embed] one is registered) - $content = do_shortcode( $content ); + $content = do_shortcode( $content, true ); // Put the original shortcodes back $shortcode_tags = $orig_shortcode_tags; @@ -318,6 +318,10 @@ class WP_Embed { * @return string Potentially modified $content. */ public function autoembed( $content ) { + // Strip newlines from all elements. + $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) ); + + // Find URLs that are on their own line. return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); } diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index aae81dd50b..f47d9a29f4 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -504,6 +504,9 @@ function wpautop( $pee, $br = true ) { // Standardize newline characters to "\n". $pee = str_replace(array("\r\n", "\r"), "\n", $pee); + // Strip newlines from all elements. + $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) ); + // Collapse line breaks before and after