php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49646 DOM LoadHTMLfile error
Submitted: 2009-09-23 19:53 UTC Modified: 2009-09-25 15:39 UTC
From: taylorms at mtaonline dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3SVN-2009-09-23 (snap) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: taylorms at mtaonline dot net
New email:
PHP Version: OS:

 

 [2009-09-23 19:53 UTC] taylorms at mtaonline dot net
Description:
------------
The line of HTML below causes DOM LoadHTMLfile to throw the following exception:

DOMDocument::loadHTMLFile() [<a href='function.DOMDocument-loadHTMLFile'>function.DOMDocument-loadHTMLFile</a>]: htmlParseEntityRef: expecting ';' in contactus.html, line: 111

Line 111 of contactus.html is a link with an onclick with multiline (";" separated) embedded javascript. The source line is shown in the code section. Note that if I create a javascript function, and reference only the function name in the 'onclick=""', the error is NOT produced (also shown). It appears the parser is getting confused with the embedded javascript in this statement.



Reproduce code:
---------------
---
From manual page: domdocument.loadhtmlfile
---

HTML Source that causes error:

<a class="social_buttons" href="http://www.facebook.com/share.php?u=aboutfaceak.com" onclick="u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;" target="_blank"><img class="social_img" src="../images/facebook_share.png" /></a>

The following code with a change to "onclick" does NOT cause an error:

<a class="social_buttons" href="http://www.facebook.com/share.php?u=aboutfaceak.com" ONCLICK="RETURN FBSHARE();" target="_blank"><img class="social_img" src="../images/facebook_share.png" /></a>



Expected result:
----------------
The onclick javascript code opens a new window with a facebook php app that uses the URL of the page where the link was clicked as the link to share on facebook. If javascript is disabled, the generic link listed in "href" is used instead of the actual current page URL.

Actual result:
--------------
The error shown in the description is thrown (and caught/logged) when the loadHTMLfile function is called with the source file containing the above source line.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-23 20:02 UTC] sjoerd@php.net
Thank you for your bug report.

If I recall correctly, ampersands need to be escaped in HTML, including in links and the like. This means that this is a bug in your HTML and not in the DOM parser. Please try to put your file through W3Cs HTML validator at http://validator.w3.org/ .
 [2009-09-23 23:12 UTC] taylorms at mtaonline dot net
sjoerd@php.net

You are correct. I first removed the & and there was no problem. I then replaced "&" with "&amp;" and still no problem. I guess I did not realize that you needed to escape & in javascript, since earlier in the HTML is a javascript with plenty of "&&"s in it. Perhaps the onclick is not parsed by the loadHTMLfile as javascript since it is enclosed in "".

Thanks for your quick reply.

Shane
 [2009-09-25 15:39 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC