3v4l.org

run code in 300+ 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:  26
compiled vars:  !0 = $html, !1 = $document, !2 = $dom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'str_replace'
          2        SEND_VAL                                                 '%2A'
          3        FETCH_CONSTANT                                   ~3      'STAR_PROTECTOR'
          4        SEND_VAL                                                 ~3
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !0, $4
    8     8        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     9        INIT_FCALL                                               'strtr'
         10        SEND_VAR                                                 !1
         11        INIT_ARRAY                                       ~7      '', '%0A'
         12        ADD_ARRAY_ELEMENT                                ~7      !0, '%21html'
         13        SEND_VAL                                                 ~7
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !1, $8
   20    16        NEW                                              $10     'DOMDocument'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !2, $10
   22    19        BEGIN_SILENCE                                    ~13     
         20        INIT_METHOD_CALL                                         !2, 'loadHTML'
         21        SEND_VAR_EX                                              !1
         22        DO_FCALL                                      0          
         23        END_SILENCE                                              ~13
   24    24      > RETURN                                                   !2
   25    25*     > 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 = 66
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 66
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 = 64
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 64
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 63
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 63
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 64
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
filename:       /in/2C0tY
function name:  simulate_filter_html_parsing
number of ops:  69
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, ->66
         17    > > FE_FETCH_R                                               $14, !2, ->66
   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, ->64
         29    > > FE_FETCH_R                                       ~21     $20, !3, ->64
         30    >   ASSIGN                                                   !4, ~21
   43    31        INIT_FCALL                                               'str_replace'
         32        FETCH_CONSTANT                                   ~23     'STAR_PROTECTOR'
         33        SEND_VAL                                                 ~23
         34        SEND_VAL                                                 '%2A'
         35        SEND_VAR                                                 !4
         36        DO_ICALL                                         $24     
         37        ASSIGN                                                   !4, $24
   47    38        INIT_FCALL                                               'preg_split'
         39        SEND_VAL                                                 '%2F%5Cs%2B%2F'
         40        INIT_FCALL                                               'str_replace'
         41        FETCH_CONSTANT                                   ~26     'STAR_PROTECTOR'
         42        SEND_VAL                                                 ~26
         43        SEND_VAL                                                 '%2A'
         44        FETCH_OBJ_R                                      ~27     !3, 'value'
         45        SEND_VAL                                                 ~27
         46        DO_ICALL                                         $28     
         47        SEND_VAR                                                 $28
         48        SEND_VAL                                                 -1
         49        SEND_VAL                                                 1
         50        DO_ICALL                                         $29     
         51        ASSIGN                                                   !5, $29
   49    52        ECHO                                                     'attr%3A+'
   50    53        INIT_FCALL                                               'var_dump'
         54        SEND_VAR                                                 !4
         55        DO_ICALL                                                 
   52    56        ISSET_ISEMPTY_CV                                 ~32     !5
         57        BOOL_NOT                                         ~33     ~32
         58      > JMPZ                                                     ~33, ->63
   53    59    >   ECHO                                                     'attr+values%3A+'
   54    60        INIT_FCALL                                               'var_dump'
         61        SEND_VAR                                                 !5
         62        DO_ICALL                                                 
   41    63    > > JMP                                                      ->29
         64    >   FE_FREE                                                  $20
   31    65      > JMP                                                      ->17
         66    >   FE_FREE                                                  $14
   58    67        ECHO                                                     '%0A%0A'
   59    68      > RETURN                                                   null

End of function simulate_filter_html_parsing

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.25 ms | 1025 KiB | 22 Q