[wp-trac] [WordPress Trac] #15600: shortcode_unautop returns emtpy string

WordPress Trac wp-trac at lists.automattic.com
Fri May 6 23:37:29 UTC 2011


#15600: shortcode_unautop returns emtpy string
-------------------------------------------------+-------------------------
 Reporter:  mdbitz                               |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  high                                 |   Milestone:  Future
Component:  Formatting                           |  Release
 Severity:  major                                |     Version:  3.0.1
 Keywords:  needs-testing has-patch needs-unit-  |  Resolution:
  tests                                          |
-------------------------------------------------+-------------------------
Changes (by mdawaffe):

 * cc: mdawaffe (added)


Comment:

 Here's a much better patch than my original.

 Both {{{do_shortcode()}}} and {{{shortcode_unautop()}}} can run into
 PREG_BACKTRACK_LIMIT_ERRORs for large inputs.

 Attached drastically reduces the execution time and backtracing for both
 functions.
  1. Constant prefix in {{{get_shortcode_regex()}}}.
  2. [http://www.softec.lu/site/RegularExpressions/UnrollingTheLoop Unroll
 the Loop] to more efficiently grab the shortcode attributes.
  3. Only look for a closing shortcode tag when the shortcode is not self
 closing.
  4. Comments for the regular expression.

 We could also similarly "Unroll the Loop" for the content between the
 opening and closing shortcode tags, but I *did not test* this patch
 against shortcodes with inner content, so I don't know if the patch even
 works, let alone if unrolling the loop there would help.

 I've also attached a some test scripts for the diff.

 Untar the tests into WordPress' ABSPATH, then run: ./shortcodes-tests.sh
 15600.2.diff

 WARNING: the test script reverts your checkout!

 My results for the tests:

 {{{
 $ ./shortcodes-tests.sh 15600.2.diff
 Reverted 'wp-includes/formatting.php'
 Reverted 'wp-includes/shortcodes.php'
 shortcode_unautop() Tests: original
 SHORT TIME: 0.0088322162628174
 LONG  TIME: 1.3537223339081
 SHORT BACKTRACE REQUIREMENT: 232
 LONG  BACKTRACE REQUIREMENT: 135670

 do_shortcode() Tests: original
 SHORT TIME: 0.027733564376831
 LONG  TIME: 2.1369636058807
 SHORT BACKTRACE REQUIREMENT: 420
 LONG  BACKTRACE REQUIREMENT: 135858

 patching file wp-includes/shortcodes.php
 patching file wp-includes/formatting.php
 shortcode_unautop() Tests: patched
 SHORT TIME: 0.0067722797393799
 LONG  TIME: 0.13501048088074
 SHORT BACKTRACE REQUIREMENT: 15
 LONG  BACKTRACE REQUIREMENT: 15

 do_shortcode() Tests: patched
 SHORT TIME: 0.021802425384521
 LONG  TIME: 0.14546251296997
 SHORT BACKTRACE REQUIREMENT: 16
 LONG  BACKTRACE REQUIREMENT: 16

 DIFFS:
 }}}

 The lack of any content after the "DIFFS:" line is good: it means there's
 no change in the outputs of the functions.

 Notice that, with respect to the input length, the time required scales
 much better, and the amount of backtracing is constant.

 My tests are pretty limited, though: just a couple simple cases embedded
 in content of varying length.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15600#comment:17>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list