3v4l.org

run code in 500+ PHP versions simultaneously
<?php const STAR_PROTECTOR = '__zqh6vxfbk3cg__'; function load($html) { $html = str_replace('*', STAR_PROTECTOR, $html); $document = <<<EOD <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head> <body>!html</body> </html> EOD; // PHP's \DOMDocument serialization adds extra whitespace when the markup // of the wrapping document contains newlines, so ensure we remove all // newlines before injecting the actual HTML body to be processed. $document = strtr($document, ["\n" => '', '!html' => $html]); $dom = new \DOMDocument(); // Ignore warnings during HTML soup loading. @$dom->loadHTML($document); return $dom; } function simulate_filter_html_parsing(string $input) { print "-----\n$input\n-----\n"; $parsed_nodes = load($input)->getElementsByTagName('body')->item(0)->childNodes; foreach ($parsed_nodes as $node) { // ⚠️ See @larowlan's https://www.drupal.org/project/drupal/issues/3280602#comment-14517052 comment if ($node->nodeType !== XML_ELEMENT_NODE) { // Skip the empty text nodes inside tags. continue; } print 'tag: '; var_dump($node->tagName); foreach ($node->attributes as $name => $attribute) { // Put back any trailing * on wildcard attribute name. $name = str_replace(STAR_PROTECTOR, '*', $name); // Put back any trailing * on wildcard attribute value and parse out // the allowed attribute values. $allowed_attribute_values = preg_split('/\s+/', str_replace(STAR_PROTECTOR, '*', $attribute->value), -1, PREG_SPLIT_NO_EMPTY); print 'attr: '; var_dump($name); // if ($attr-) if (!empty($allowed_attribute_values)) { print 'attr values: '; var_dump($allowed_attribute_values); } } } print "\n\n"; } // ⚠️ Uncomment this if you want to convince yourself this really is running for all PHP versions // print phpversion() . "\n"; simulate_filter_html_parsing('<foo data-*>'); simulate_filter_html_parsing('<foo data-*="foo bar">'); simulate_filter_html_parsing('<__preprocessed-global-attribute__ data-*="foo bar">'); // ⚠️ This is the specific example @larowlan cited at https://www.drupal.org/project/drupal/issues/3280602#comment-14517052 simulate_filter_html_parsing('<__preprocessed-wildcard-text-container__ class="text-align-left text-align-center text-align-right text-align-justify" />'); // ⚠️ 3vl.org unfortunately has disabled phpinfo for security reasons… so we cannot check the libxml version //var_dump(phpinfo(INFO_MODULES));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2C0tY
function name:  (null)
number of ops:  14
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                                'STAR_PROTECTOR', '__zqh6vxfbk3cg__'
   65     1        INIT_FCALL                                                   'simulate_filter_html_parsing'
          2        SEND_VAL                                                     '%3Cfoo+data-%2A%3E'
          3        DO_FCALL                                          0          
   66     4        INIT_FCALL                                                   'simulate_filter_html_parsing'
          5        SEND_VAL                                                     '%3Cfoo+data-%2A%3D%22foo+bar%22%3E'
          6        DO_FCALL                                          0          
   67     7        INIT_FCALL                                                   'simulate_filter_html_parsing'
          8        SEND_VAL                                                     '%3C__preprocessed-global-attribute__+data-%2A%3D%22foo+bar%22%3E'
          9        DO_FCALL                                          0          
   69    10        INIT_FCALL                                                   'simulate_filter_html_parsing'
         11        SEND_VAL                                                     '%3C__preprocessed-wildcard-text-container__+class%3D%22text-align-left+text-align-center+text-align-right+text-align-justify%22+%2F%3E'
         12        DO_FCALL                                          0          
   72    13      > RETURN                                                       1

Function load:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2C0tY
function name:  load
number of ops:  20
compiled vars:  !0 = $html, !1 = $document, !2 = $dom
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
    6     1        FETCH_CONSTANT                                       ~3      'STAR_PROTECTOR'
          2        FRAMELESS_ICALL_3                str_replace         ~4      '%2A', ~3
          3        OP_DATA                                                      !0
          4        ASSIGN                                                       !0, ~4
    8     5        ASSIGN                                                       !1, '%3C%21DOCTYPE+html+PUBLIC+%22-%2F%2FW3C%2F%2FDTD+XHTML+1.0+Strict%2F%2FEN%22+%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-strict.dtd%22%3E%0A%3Chtml+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%0A%3Chead%3E%3Cmeta+http-equiv%3D%22Content-Type%22+content%3D%22text%2Fhtml%3B+charset%3Dutf-8%22+%2F%3E%3C%2Fhead%3E%0A%3Cbody%3E%21html%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   18     6        INIT_ARRAY                                           ~7      '', '%0A'
          7        ADD_ARRAY_ELEMENT                                    ~7      !0, '%21html'
          8        FRAMELESS_ICALL_2                strtr               ~8      !1, ~7
          9        ASSIGN                                                       !1, ~8
   20    10        NEW                                                  $10     'DOMDocument'
         11        DO_FCALL                                          0          
         12        ASSIGN                                                       !2, $10
   22    13        BEGIN_SILENCE                                        ~13     
         14        INIT_METHOD_CALL                                             !2, 'loadHTML'
         15        SEND_VAR_EX                                                  !1
         16        DO_FCALL                                          0          
         17        END_SILENCE                                                  ~13
   24    18      > RETURN                                                       !2
   25    19*     > RETURN                                                       null

End of function load

Function simulate_filter_html_parsing:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 60
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 60
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 58
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 58
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 57
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 57
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 58
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
filename:       /in/2C0tY
function name:  simulate_filter_html_parsing
number of ops:  63
compiled vars:  !0 = $input, !1 = $parsed_nodes, !2 = $node, !3 = $attribute, !4 = $name, !5 = $allowed_attribute_values
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
   29     1        ROPE_INIT                                         3  ~7      '-----%0A'
          2        ROPE_ADD                                          1  ~7      ~7, !0
          3        ROPE_END                                          2  ~6      ~7, '%0A-----%0A'
          4        ECHO                                                         ~6
   30     5        INIT_FCALL                                                   'load'
          6        SEND_VAR                                                     !0
          7        DO_FCALL                                          0  $9      
          8        INIT_METHOD_CALL                                             $9, 'getElementsByTagName'
          9        SEND_VAL_EX                                                  'body'
         10        DO_FCALL                                          0  $10     
         11        INIT_METHOD_CALL                                             $10, 'item'
         12        SEND_VAL_EX                                                  0
         13        DO_FCALL                                          0  $11     
         14        FETCH_OBJ_R                                          ~12     $11, 'childNodes'
         15        ASSIGN                                                       !1, ~12
   31    16      > FE_RESET_R                                           $14     !1, ->60
         17    > > FE_FETCH_R                                                   $14, !2, ->60
   34    18    >   FETCH_OBJ_R                                          ~15     !2, 'nodeType'
         19        IS_NOT_IDENTICAL                                             ~15, 1
         20      > JMPZ                                                         ~16, ->22
   36    21    > > JMP                                                          ->17
   39    22    >   ECHO                                                         'tag%3A+'
   40    23        INIT_FCALL                                                   'var_dump'
         24        FETCH_OBJ_R                                          ~17     !2, 'tagName'
         25        SEND_VAL                                                     ~17
         26        DO_ICALL                                                     
   41    27        FETCH_OBJ_R                                          ~19     !2, 'attributes'
         28      > FE_RESET_R                                           $20     ~19, ->58
         29    > > FE_FETCH_R                                           ~21     $20, !3, ->58
         30    >   ASSIGN                                                       !4, ~21
   43    31        FETCH_CONSTANT                                       ~23     'STAR_PROTECTOR'
         32        FRAMELESS_ICALL_3                str_replace         ~24     ~23, '%2A'
         33        OP_DATA                                                      !4
         34        ASSIGN                                                       !4, ~24
   47    35        INIT_FCALL                                                   'preg_split'
         36        SEND_VAL                                                     '%2F%5Cs%2B%2F'
         37        FETCH_CONSTANT                                       ~26     'STAR_PROTECTOR'
         38        FETCH_OBJ_R                                          ~27     !3, 'value'
         39        FRAMELESS_ICALL_3                str_replace         ~28     ~26, '%2A'
         40        OP_DATA                                                      ~27
         41        SEND_VAL                                                     ~28
         42        SEND_VAL                                                     -1
         43        SEND_VAL                                                     1
         44        DO_ICALL                                             $29     
         45        ASSIGN                                                       !5, $29
   49    46        ECHO                                                         'attr%3A+'
   50    47        INIT_FCALL                                                   'var_dump'
         48        SEND_VAR                                                     !4
         49        DO_ICALL                                                     
   52    50        ISSET_ISEMPTY_CV                                     ~32     !5
         51        BOOL_NOT                                             ~33     ~32
         52      > JMPZ                                                         ~33, ->57
   53    53    >   ECHO                                                         'attr+values%3A+'
   54    54        INIT_FCALL                                                   'var_dump'
         55        SEND_VAR                                                     !5
         56        DO_ICALL                                                     
   41    57    > > JMP                                                          ->29
         58    >   FE_FREE                                                      $20
   31    59      > JMP                                                          ->17
         60    >   FE_FREE                                                      $14
   58    61        ECHO                                                         '%0A%0A'
   59    62      > RETURN                                                       null

End of function simulate_filter_html_parsing

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.29 ms | 2036 KiB | 20 Q