php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80743 DOMDocument saveHTML() creates invalid source element
Submitted: 2021-02-13 10:01 UTC Modified: 2021-02-18 11:38 UTC
From: ic dot czech+php at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: DOM XML related
PHP Version: 8.0.2 OS: linux & win
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 + 20 = ?
Subscribe to this entry?

 
 [2021-02-13 10:01 UTC] ic dot czech+php at gmail dot com
Description:
------------
Native DOMDocument's method saveHTML() creates paired tag from picture/video source element, but according to https://www.w3.org/TR/2011/WD-html5-author-20110809/the-source-element.html it should be unpaired element. It works well with another unpaired elements like meta, img, br, hr, … . But it filed with source ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source ) .




Test script:
---------------
<?php

const ELEMENT_NAME = 'source'; // meta / img / br / hr

$document = new DOMDocument( '1.0', 'UTF-8' );
$element = $document->createElement(ELEMENT_NAME);
$document->appendChild($element);
echo $document->saveHTML(); // writes '<source></source>' but according to https://www.w3.org/TR/2011/WD-html5-author-20110809/the-source-element.html it should be '<source>'


Expected result:
----------------
<source>

Actual result:
--------------
<source></source>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-18 11:38 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-02-18 11:38 UTC] cmb@php.net
libxml2 doesn't know about <source> elements[1], and there is not
much we can do about that.  Consider to report this to upstream[2]
(although I presume that they are aware of this issue).

[1] <https://github.com/GNOME/libxml2/blob/cbe1212db6e22fa92c33242c3ce089476585f872/HTMLparser.c#L610>
[2] <http://www.xmlsoft.org/bugs.html>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 04:01:30 2024 UTC