php.net |  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
Status: Closed Package: DOM XML related
PHP Version: 5.3.0 OS: Windows XP
Private report: No CVE-ID:
 [2009-07-20 09:44 UTC] php at bouchery dot fr
Description:
------------
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:
---------------
<?php

$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();
$doc->saveHTMLFile('result.html'); 
?>

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


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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-20 14:53 UTC] jani@php.net
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
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php 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

 [2010-04-02 22:08 UTC] rrichards@php.net
Automatic comment from SVN on behalf of rrichards
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=297374
Log: fix bug #48983 (DomDocument : saveHTMLFile wrong charset)
 [2010-04-02 22:09 UTC] rrichards@php.net
-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] rrichards@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

crash was from older libxml2 version
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 20:01:57 2014 UTC