php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63477 DOMDocument::loadHtml error in parsing attribute names
Submitted: 2012-11-09 22:08 UTC Modified: 2012-11-09 22:18 UTC
From: ryanve at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3.18 OS: Linux
Private report: No CVE-ID: None
 [2012-11-09 22:08 UTC] ryanve at gmail dot com
Description:
------------
HTML data attribute names can contain periods:

`<p data-1.5>This is valid in HTML5</p>`

DOMDocument::loadHtml does not properly parse the line above due to the period. 
It changes the 1.5 to 1 and/or throws an error:

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: error parsing attribute 
name in Entity

Please see:
http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes
http://stackoverflow.com/questions/13283699/sanitize-attribute-name

I am using Dreamhost:
PHP version: 5.3.13 (FastCGI)
PHP build date: 2012-06-07

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

# this throws an error:
$dom = new DOMDocument;
$dom->loadHtml('<a data-1.5="value"></a>');
echo $dom->saveHtml();

# this works fine:
$dom = new DOMDocument;
$a = $dom->createElement('a');
$a->setAttribute('data-1.5', 'value');
$dom->appendChild($a);
echo $dom->saveHtml();


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-09 22:18 UTC] rasmus@php.net
This doesn't actually have much to do with PHP. This completely depends on 
whether the version of libxml2 you are using has support for this part of HTML5. 
I haven't looked into it, but I know there were HTML5 additions in libxml2 
version 2.8.0. So in order to track this down, figure out which version of 
libxml2 you are using. Head over to http://xmlsoft.org/ and see if there is a 
more recent version that handles your case. If there isn't, open a feature 
request with them. If there is, ask Dreamhost to update their libxml2.
 [2012-11-09 22:18 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-11-09 22:34 UTC] ryanve at gmail dot com
@rasmus Thanks - I looked in phpinfo and the libxml version was 2.6.32 - I'll ask 
Dreamhost about upgrading.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 00:01:30 2024 UTC