html5lib / gcode-import

Automatically exported from code.google.com/p/html5lib. Purely archival.
Other
7 stars 8 forks source link

Failure with custom namespace elements (PHP lib) #131

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Using a custom namespaced element (apart from the hardcoded SVG and MathML 
namespaces) causes a failure with DOMDocument::createElementNS(). For 
instance the following piece of HTML:

<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
  <fb:login-button>Facebook Connect</fb:login-button>
</body>
</html>

It causes the following warning (which should be an error, since the 
function returns nothing):

PHP Warning:  DOMDocument::createElementNS(): Namespace Error in 
TreeBuilder.php on line 3055

The problem is that TreeBuilder doesn't care of the XMLNS declarations in 
the HTML tag when creating elements, and it never uses the defined 
namespace URL when building elements. Thus, when calling 
DOMDocument::createElementNS() for 'fb:login_button' it tries to create a 
namespaced element using null as the namespaceURI, which causes a failure.

I attached a patch, which fixes the problem.

Original issue reported on code.google.com by Ysbadda...@gmail.com on 5 Jan 2010 at 3:26

Attachments:

GoogleCodeExporter commented 9 years ago
That patch is wrong: per the HTML 5 spec, that should create an element whose 
localname is "fb:login-button" and whose namespaceURI is 
"http://www.w3.org/1999/
xhtml".

What we should be doing is coercing what we get into an XML infoset.

Original comment by geoffers on 5 Jan 2010 at 6:56

GoogleCodeExporter commented 9 years ago
I did some experimentation with XML namespaces and PHP's DOM implementation a 
while
back, and I think I decided that the situation was absolutely hopeless and that 
I
could not get DOM to do precisely what was necessary to make conformance.

Others are invited to try to get the right semantics, but resolution for this 
bug
does not seem hopeful, which is very sad.

Original comment by ezy...@mit.edu on 5 Jan 2010 at 7:00

GoogleCodeExporter commented 9 years ago
I heavily simplified the patch, which was wrong as geoffers pointed out.

I changed Treebuilder::insertElement() to create an element with 
"http://www.w3.org/1999/xhtml" as the namespaceURI whenever there is a COLON in 
the 
localname. I also removed what extracted XMLNS declarations (since that's 
useless).

Is it any better, per the HTML 5 spec?

Original comment by Ysbadda...@gmail.com on 6 Jan 2010 at 10:32

Attachments:

GoogleCodeExporter commented 9 years ago
This patch really needs to be merged into the main branch as it does indeed fix 
an issue that, according to some googling is biting a whole lot of folks int he 
bottom.

the fb:whatever tags are really quite common.

Original comment by dougmel...@gmail.com on 31 Aug 2012 at 3:37