Make WordPress Core

Ticket #29450: preg-debug.php

File preg-debug.php, 3.7 KB (added by miqrogroove, 11 years ago)

We want to know if this script causes a crash for anyone.

Line 
1<?php
2
3// Simulated Post Content
4$text = 'hello world. [myshortcode arg1="Aenean consectetur ipsum ante, vel egestas enim tincidunt quis. Pellentesque vitae congue neque, vel mattis ante. In vitae tempus nunc. Etiam adipiscing enim sed condimentum ultrices. Aenean consectetur ipsum ante, vel egestas enim tincidunt qu. In vitae tempus nunc. In vitaentbnbsdgsdsdgsdhsdhdsdhdsh Aenean consectetur ipsum ante, vel egestas enim tincidunt quis. Pellentesque vitae congue neque, vel mattis ante. In vitae tempus nunc. Etiam adipiscing enim sed condimentum ultrices. Aenean consectetur ipsum ante, vel egestas enim tincidunt qu. In vitae tempus nunc. In vitaentbnbsdgsdsdgsdhsdhdsdhdsh" /] hello world.';
5
6// Simulated Shortcode Registry
7$shortcode_tags = array (
8  'embed' => '__return_false',
9  'wp_caption' => 'img_caption_shortcode',
10  'caption' => 'img_caption_shortcode',
11  'gallery' => 'gallery_shortcode',
12  'playlist' => 'wp_playlist_shortcode',
13  'audio' => 'wp_audio_shortcode',
14  'video' => 'wp_video_shortcode',
15);
16
17
18// Simulation
19
20
21function preg_errtxt($errcode)
22{
23    static $errtext;
24
25    if (!isset($errtxt))
26    {
27        $errtext = array();
28        $constants = get_defined_constants(true);
29        foreach ($constants['pcre'] as $c => $n) if (preg_match('/_ERROR$/', $c)) $errtext[$n] = $c;
30    }
31
32    return array_key_exists($errcode, $errtext)? $errtext[$errcode] : NULL;
33}               
34
35        $tagnames = array_keys( $shortcode_tags );
36        $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
37        $tagregexp = "(?:$tagregexp)(?![\\w-])"; // Excerpt of get_shortcode_regex().
38
39        // Look for shortcodes and HTML elements.
40
41        $regex =  '/('                  // Capture the entire match.
42                .       '<'             // Find start of element.
43                .       '(?(?=!--)'     // Is this a comment?
44                .               '.+?--\s*>'     // Find end of comment
45                .       '|'
46                .               '[^>]+>'        // Find end of element
47                .       ')'
48                . '|'
49                .       '\['            // Find start of shortcode.
50                .       '\[?'           // Shortcodes may begin with [[
51                .       '\/?'           // Closing slash may precede name.
52                .       $tagregexp      // Only match registered shortcodes, because performance.
53                .       '[^\[\]]*'      // Shortcodes do not contain other shortcodes.
54                .       '\]'            // Find end of shortcode.
55                .       '\]?'           // Shortcodes may end with ]]
56                . ')/s';
57
58        ini_set('pcre.backtrack_limit', 10);
59        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
60        echo "<br />\n10: ", preg_errtxt(preg_last_error());
61       
62        ini_set('pcre.backtrack_limit', 15);
63        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
64        echo "<br />\n15: ", preg_errtxt(preg_last_error());
65       
66        ini_set('pcre.backtrack_limit', 20);
67        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
68        echo "<br />\n20: ", preg_errtxt(preg_last_error());
69       
70        ini_set('pcre.backtrack_limit', 100);
71        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
72        echo "<br />\n100: ", preg_errtxt(preg_last_error());
73       
74        ini_set('pcre.backtrack_limit', 1000);
75        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
76        echo "<br />\n1000: ", preg_errtxt(preg_last_error());
77       
78        ini_set('pcre.backtrack_limit', 10000);
79        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
80        echo "<br />\n10000: ", preg_errtxt(preg_last_error());
81       
82        ini_set('pcre.backtrack_limit', 100000);
83        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
84        echo "<br />\n100000: ", preg_errtxt(preg_last_error());
85       
86        ini_set('pcre.backtrack_limit', 1000000);
87        $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
88        echo "<br />\n1000000: ", preg_errtxt(preg_last_error());
89       
90       
91?>