[wp-trac] [WordPress Trac] #52517: Shortcodes inside AMP tags do not work

WordPress Trac noreply at wordpress.org
Sat Feb 13 14:39:20 UTC 2021


#52517: Shortcodes inside AMP tags do not work
--------------------------+-----------------------------
 Reporter:  Krstarica     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Shortcodes    |    Version:  5.6.1
 Severity:  critical      |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Example code to demonstrate shortcode not working inside AMP tag:
 {{{
 add_shortcode ( 'test', '__return_false' );
 echo do_shortcode('<amp-ad width=320 height=100 [test]>');
 }}}
 displays
 {{{
 <amp-ad width=320 height=100 [test]>
 }}}

 Example code to demonstrate shortcode working inside regular tag:
 {{{
 add_shortcode ( 'test', '__return_false' );
 echo do_shortcode('<img width=320 height=100 [test]>');exit;
 }}}
 displays
 {{{
 <img width=320 height=100 >
 }}}

 The reason is wp_kses_attr_parse function not supporting tags with
 hyphens. All AMP tags contain hyphen, e.g. "amp-ad":
 https://amp.dev/documentation/guides-and-
 tutorials/learn/spec/amphtml/?format=websites#html-tags


 {{{
 var_dump(wp_kses_attr_parse( '<amp-ad width=320 height=100>' ))
 }}}
 displays
 {{{
 bool(false)
 }}}
 instead of
 {{{
 array(4) {
   [0]=>
   string(7) "<amp-ad "
   [1]=>
   string(10) "width=320 "
   [2]=>
   string(10) "height=100"
   [3]=>
   string(1) ">"
 }
 }}}

 The fix is to change function wp_kses_attr_parse( $element ) in wp-
 includes/kses.php from:
 {{{
 $valid = preg_match( '%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%',
 $element, $matches );
 }}}
 to
 {{{
 $valid = preg_match( '%^(<\s*)(/\s*)?([a-zA-Z0-9\-]+\s*)([^>]*)(>?)$%',
 $element, $matches );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52517>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list