PHP  
 PHP_HEAD
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/dom/tests/bug76738.phpt ('Bug #76738 Wrong handling of output buffer')

Script

1: <?php declare(strict_types=1);
2:
$test_string base64_decode('PGRpdiBjbGFzcz0idGlueW1jZS1nZW5lcmF0ZWQtcm9vdC1ibG9jayIgc3R5bGU9Im1hcmdpbjogMHB4OyBwYWRkaW5nOiAwcHg7Ij4KPGRpdiBzdHlsZT0iZmxvYXQ6IHJpZ2h0OyI+PGltZyBhbHQ9IkZvdG8gUmVpbmRsIEhhcmFsZCIgc3JjPSIvcnRlL3VwbG9hZC9mb3RvLmpwZyIgc3R5bGU9IndpZHRoOiAyNTBweDsgaGVpZ2h0OiAyNDlweDsiPjwvZGl2Pgo8ZGl2IHN0eWxlPSJ3aGl0ZS1zcGFjZTogbm93cmFwOyI+CjxwIHN0eWxlPSJtYXJnaW46IDBweDsiPlJlaW5kbCBIYXJhbGQmdXVtbDs8YnI+IFNpZWdmcmllZGdhc3NlIDIyLTI0LzIvNDxicj4gMTIxMCBXaWVuPGJyPiAoKzQzKSAwNjc2IDQwIDIyMSA0MDxicj4gW2JlZm9yZWxpbmtzXTxhIGhyZWY9Ii9zaG93X2NvbnRlbnQucGhwP3NpZD0xMDciPnN1cHBvcnRAcmhzb2Z0Lm5ldDwvYT48YnI+IFtiZWZvcmVsaW5rc108YSBocmVmPSIvcmVpbmRsLWhhcmFsZC52Y2YiPlYtQ2FyZCBoZXJ1bnRlcmxhZGVuPC9hPjxicj4gW2JlZm9yZWxpbmtzXTxhIHRhcmdldD0iX2JsYW5rIiBocmVmPSIvZ3BnL3N1cHBvcnRfcmhzb2Z0Lm5ldC5wdWIudHh0Ij5NYWlsIEdQRy1LZXk8L2E+PC9wPgo8L2Rpdj4KPGRpdiBzdHlsZT0iZmxvYXQ6IG5vbmU7IHBhZGRpbmctdG9wOiAxNXB4OyI+Cjxocj4KPGI+R2VidXJ0c2Rhd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gQ2xhdWRlIFZhbiBEYW1tZSwgU3lsdmVzdGVyIFN0YWxsb25lLCBTdGV2ZW4gU2VhZ2FsLCBMb3JlbnpvIExhbWFzLCBOaWNvbGFzIENhZ2UsIFJpY2hhcmQgRGVhbiBBbmRlcnNvbiwgRGVuemVsIFdhc2hpbmd0b24sIENocmlzdG9waGVyIExhbWJlcnQsIE1lZyBSeWFuLCBTYXJhaCBNaWNoZWxsZSBHZWxsYXIsIEFtYW5kYSBUYXBwaW5nIC4uLi48L2xpPgo8bGk+SyZvdW1sO25pZ3JlaWNoIGRlciBIaW1tZWwsIEhlcnIgZGVyIFJpbmdlLCBIaWdobGFuZGVyLCBDb24gQWlyLCBUaGUgUm9jaywgU3RhcmdhdGUsIEluZGVwZW5kZW5jZSBEYXksIFp1bSB0Jm91bWw7dGVuIGZyZWlnZWdlYmVuLCBIYXJkIFRvIEtpbGwsIFRoZSBQYXRyaW90LCBSYW1ibywgUm9ja3ksIEhhcnRlIFppZWxlLCBUaW1lY29wLCBCZXN0IE9mIFRoZSBCZXN0LCBCcnVjZSBMZWUgU3RvcnkgLi4uLjwvbGk+CjxsaT5TdGFyZ2F0ZSwgQW5kcm9tZWRhLCBIaWdod2F5IFRvIEhlbGwsIFJlbmVnYWRlLCBOaWtpdGEsIFByb2ZpbGVyLCBDU0ksIERhcmsgQW5nZWwsIEJ1ZmZ5LCBDaGFybWVkPC9saT4KPC91bD4KPC9kaXY+CjwvZGl2Pgo=');
3:
$after_load = (new rh_rte_helper_debug)->on_load($test_string);
4:
5:
var_dump($after_load === $test_string);
6:
7: final class 
rh_rte_helper_debug
8:
{
9:  public 
$errors = [];
10:
11:  public function 
on_load(string $content): string
12:  
{
13:   
$content utf8_encode($content);
14:   
$content $this->add_outer_html($content);
15:   
$content $this->remove_garbage($content);
16:   
$has_root_block $this->has_root_block($content);
17:   if(!
$has_root_block)
18:   {
19:    
$content $this->add_root_block($content);
20:   }
21:   
$content $this->remove_outer_html($content);
22:   
$content mb_convert_encoding($content'html-entities''UTF-8');
23:   
$content utf8_decode($content);
24:   return 
$content;
25:  }
26:
27:  private function 
has_root_block(string $content): bool
28:  
{
29:   
$return $content;
30:   
$doc $this->get_dom($content);
31:   if(
$doc != FALSE)
32:   {
33:    
$xpath = ($doc != FALSE) ? new DomXpath($doc) : FALSE;
34:    if(
$xpath != FALSE)
35:    {
36:     
$path '//*[contains(concat(" ", normalize-space(@class), " "), "tinymce-generated-root-block")]';
37:     
$nodes $xpath->query($path);
38:     
$nodes_idx = ($nodes != FALSE) ? $nodes->length 0;
39:     if(
$nodes_idx 0)
40:     {
41:      return 
TRUE;
42:     }
43:     else
44:     {
45:      return 
FALSE;
46:     }
47:    }
48:    else
49:    {
50:     return 
FALSE;
51:    }
52:   }
53:   else
54:   {
55:    return 
FALSE;
56:   }
57:  }
58:
59:  private function 
add_root_block(string $content): string
60:  
{
61:   
$return $content;
62:   
$doc $this->get_dom($content);
63:   if(
$doc != FALSE)
64:   {
65:    
$xpath = ($doc != FALSE) ? new DomXpath($doc) : FALSE;
66:    if(
$xpath != FALSE)
67:    {
68:     
$path '//*[contains(concat(" ", normalize-space(@class), " "), "tinymce-generated-root-block")]';
69:     
$nodes $xpath->query($path);
70:     
$nodes_idx = ($nodes != FALSE) ? $nodes->length 0;
71:     if(
$nodes_idx == 0)
72:     {
73:      
$root_div $doc->createElement('div');
74:      
$root_div->setAttribute('class''tinymce-generated-root-block');
75:      
$root_div->setAttribute('style''margin: 0px; padding: 0px;');
76:      
$body $doc->getElementsByTagName('body')->item(0);
77:      if(
$body !== NULL)
78:      {
79:       while(
$body->childNodes->length 0)
80:       {
81:        
$root_div->appendChild($body->childNodes->item(0));
82:       }
83:       
$body->appendChild($root_div);
84:       
$return $doc->saveHTML();
85:      }
86:     }
87:    }
88:   }
89:   return 
$return;
90:  }
91:
92:  private function 
add_outer_html(string $content): string
93:  
{
94:   return 
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Tidy</title></head><body>' $content '</body></html>';
95:  }
96:
97:  private function 
remove_root_block(string $content): string
98:  
{
99:   return 
$this->remove_block($content'tinymce-generated-root-block');
100:  }
101:
102:  private function 
remove_garbage(string $content): string
103:  
{
104:   return 
$this->remove_block($content'tinymce-garbage-root-block');
105:  }
106:
107:  private function 
get_dom(string $htmlbool $add_outer_html=TRUE): DOMDocument
108:  
{
109:   
$use_internal_errors      libxml_use_internal_errors(TRUE);
110:   
$dom                      = new DOMDocument;
111:   
$dom->resolveExternals    FALSE;
112:   
$dom->preserveWhiteSpace  TRUE;
113:   
$dom->strictErrorChecking FALSE;
114:   
$dom->formatOutput        TRUE;
115:   
$dom->recover             TRUE;
116:   
$dom->validateOnParse     TRUE;
117:   
$dom->substituteEntities  FALSE;
118:   
$html                     mb_convert_encoding($html'HTML-ENTITIES''UTF-8');
119:   
$options 0;
120:   if(!
$add_outer_html)
121:   {
122:    
$options LIBXML_HTML_NOIMPLIED;
123:   }
124:   
$options $options LIBXML_HTML_NODEFDTD;
125:   
$loaded = @$dom->loadHTML('<?xml encoding="UTF-8">' $html$options);
126:   if(!
$loaded)
127:   {
128:    
$dom FALSE;
129:    
$this->errors libxml_get_errors();
130:   }
131:   else
132:   {
133:    foreach(
$dom->childNodes as $item)
134:    {
135:     if(
$item->nodeType == XML_PI_NODE)
136:     {
137:      
$dom->removeChild($item);
138:     }
139:    }
140:    
$dom->encoding 'UTF-8';
141:   }
142:   
libxml_clear_errors();
143:   
libxml_use_internal_errors($use_internal_errors);
144:   return 
$dom;
145:  }
146:
147:  private function 
remove_outer_html(string $content): string
148:  
{
149:   
$return $content;
150:   
$doc $this->get_dom($content);
151:   if(
$doc !== FALSE)
152:   {
153:    if(
$doc->doctype !== NULL)
154:    {
155:     
$doc->doctype->parentNode->removeChild($doc->doctype);
156:    }
157:    
$html $doc->getElementsByTagName('html')->item(0);
158:    if(
$html !== NULL)
159:    {
160:     
$fragment $doc->createDocumentFragment();
161:     while(
$html->childNodes->length 0)
162:     {
163:      
$childNode $html->childNodes->item(0);
164:      
$fragment->appendChild($childNode);
165:     }
166:     
$html->parentNode->replaceChild($fragment$html);
167:    }
168:    
$body $doc->getElementsByTagName('body')->item(0);
169:    if(
$body !== NULL)
170:    {
171:     
$return '';
172:     
$fragment $doc->createDocumentFragment();
173:     while(
$body->childNodes->length 0)
174:     {
175:      
$childNode $body->childNodes->item(0);
176:      
$fragment->appendChild($childNode);
177:      
$return .= $doc->saveHTML($childNode);
178:     }
179:     
$body->parentNode->replaceChild($fragment$body);
180:    }
181:    else
182:    {
183:     
$return $doc->saveHTML();
184:    }
185:   }
186:   return 
$return;
187:  }
188:
189:  private function 
remove_block(string $contentstring $class='tinymce-generated-root-block'): string
190:  
{
191:   
$return $content;
192:   
$doc $this->get_dom($content);
193:   if(
$doc != FALSE)
194:   {
195:    
$xpath = ($doc != FALSE) ? new DomXpath($doc) : FALSE;
196:    if(
$xpath != FALSE)
197:    {
198:     
$path '//*[contains(concat(" ", normalize-space(@class), " "), "'.$class.'")]';
199:     
$nodes $xpath->query($path);
200:     
$nodes_idx = ($nodes != FALSE) ? $nodes->length 0;
201:     if(
$nodes_idx 0)
202:     {
203:      foreach(
$nodes as $node)
204:      {
205:       
$fragment $doc->createDocumentFragment();
206:       while(
$node->childNodes->length 0)
207:       {
208:        
$childNode $node->childNodes->item(0);
209:        if(
$childNode->nodeType == XML_TEXT_NODE)
210:        {
211:         
$fragment->appendChild($doc->createTextNode($childNode->nodeValue));
212:         
$childNode->parentNode->removeChild($childNode);
213:        }
214:        else
215:        {
216:         
$fragment->appendChild($childNode);
217:        }
218:       }
219:       
$node->parentNode->replaceChild($fragment$node);
220:      }
221:      
$return $doc->saveHTML();
222:     }
223:    }
224:   }
225:   return 
$return;
226:  }
227: }
228:

Expected

bool(true)

Output

Warning: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' (this will throw an Error in a future version of PHP) in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124

Warning: A non-numeric value encountered in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124

Warning: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' (this will throw an Error in a future version of PHP) in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124

Warning: A non-numeric value encountered in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124

Warning: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' (this will throw an Error in a future version of PHP) in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124

Warning: A non-numeric value encountered in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124
bool(true)

Diff

001+ Warning: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' (this will throw an Error in a future version of PHP) in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124
001- bool(true)
002+ 
003+ Warning: A non-numeric value encountered in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124
004+ 
005+ Warning: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' (this will throw an Error in a future version of PHP) in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124
006+ 
007+ Warning: A non-numeric value encountered in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124
008+ 
009+ Warning: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' (this will throw an Error in a future version of PHP) in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124
010+ 
011+ Warning: A non-numeric value encountered in /var/php_gcov/PHP_HEAD/ext/dom/tests/bug76738.php on line 124
012+ bool(true)

 

Generated at Mon, 14 Jan 2019 03:56:25 +0000 (4 days ago)

Copyright © 2005-2019 The PHP Group
All rights reserved.