|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48983 DomDocument : saveHTMLFile wrong charset
Submitted: 2009-07-20 09:44 UTC Modified: 2010-04-02 22:09 UTC
From: php at bouchery dot fr Assigned: rrichards (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.3.0 OS: Windows XP
Private report: No CVE-ID: None
 [2009-07-20 09:44 UTC] php at bouchery dot fr
When using DomDocument to generate HTML. If I'm trying to add the content-type, and generate a file with "saveHTMLfile", PHP crash and charset is not correctly defined (Always UTF-8).
With "saveHTML", it works fine.

Reproduce code:

$doc = new DOMDocument('1.0','iso-8859-1');
$doc->formatOutput = true;

$root = $doc->createElement('html');
$root = $doc->appendChild($root);

$head = $doc->createElement('head');
$head = $root->appendChild($head);

$title = $doc->createElement('title');
$title = $head->appendChild($title);

$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);

$meta = $doc->createElement('meta'); 
$meta = $head->appendChild($meta);
$meta->setAttribute('http-equiv', 'Content-Type'); 
$meta->setAttribute('content', 'text/html; charset=ISO-8859-1'); 

echo $doc->saveHTML();

Expected result:
No crash, output is :
<title>This is the title</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
And "result.html" must contains : 
<title>This is the title</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

Actual result:
PHP process crash
Output : 
<title>This is the title</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is the title</title>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-20 14:53 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read for *NIX and for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

 [2009-07-20 16:03 UTC] php at bouchery dot fr
Entry point   php+2fa2 
Create time   20/07/2009 18:00:24 
Time spent in user mode   0 Days 0:0:0.31 
Time spent in kernel mode   0 Days 0:0:0.78 

Function     Arg 1     Arg 2     Arg 3   Source 
php5ts!DllMain+c2     00000000     00000000     00000000    

PHP5TS!DLLMAIN+C2WARNING - DebugDiag was not able to locate debug 
symbols for php5ts.dll, so the information below may be incomplete.

Exception_C0000005.dmp the assembly instruction at php5ts!DllMain+c2 
in C:\bin\php-5.3.0\php5ts.dll from The PHP Group has caused an access 
violation exception (0xC0000005) when trying to read from memory 
location 0x64756f70 on thread 0

Module Information 
Image Name: C:\bin\php-5.3.0\php5ts.dll   Symbol Type:  Export 
Base address: 0x10000000   Time Stamp:  Mon Jun 29 22:53:15 2009  
Checksum: 0x00579fbc   Comments:   
COM DLL: False   Company Name:  The PHP Group 
ISAPIExtension: False   File Description:  PHP Script Interpreter 
ISAPIFilter: False   File Version:  5.3.0 
Managed DLL: False   Internal Name:  PHP Script Interpreter 
VB DLL: False   Legal Copyright:  Copyright ? 1997-2009 The PHP Group 
Loaded Image Name:  php5ts.dll   Legal Trademarks:  PHP 
Mapped Image Name:     Original filename:  php5ts.dll 
Module name:  php5ts   Private Build:   
Single Threaded:  False   Product Name:  PHP 
Module Size:  5,61 MBytes   Product Version:  5.3.0 
Symbol File Name:  php5ts.dll   Special Build:  &)
 [2010-04-02 22:08 UTC]
Automatic comment from SVN on behalf of rrichards
Log: fix bug #48983 (DomDocument : saveHTMLFile wrong charset)
 [2010-04-02 22:09 UTC]
-Summary: DomDocument : saveHTMLFile wrong charset and crash +Summary: DomDocument : saveHTMLFile wrong charset -Status: Open +Status: Closed -Assigned To: +Assigned To: rrichards
 [2010-04-02 22:09 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

crash was from older libxml2 version
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 17:01:33 2024 UTC