Menu

#56 Attribute values overwritten,behaviour differs from browsers

closed
None
2018-12-08
2010-09-07
Rayo
No

simple_html_dom v1.1

If a HTML-tag defines an attribute twice (or more times) the simple_html_dom-parser will (only) consider the last appearance / the last value within the HTML-tag.
Browsers like IE and Firefox, however, only consider the first appearance / the first value.

==========================================

Example HTML-code:
While usual browsers will open the link (SourceForge-page) in the same window/tab, the simple_html_dom-parser states the link would be opened in a new (blank) windows/tab.

<html><body>

Self First

</body></html>

==========================================

Problematic Code-Function:
simple_html_dom::parse_attr()

==========================================

Proposed solution:
The following code to be added as first line of simple_html_dom::parse_attr()

if (isset($node->attr[$name]))
return;

Discussion

  • msuspartan

    msuspartan - 2013-11-26

    This fix causes attribute processing to stop after encountering a duplicate.

    <img alt="first" alt="second" src="awesome_image.jpg"/>

    parses to

    <img alt="first">

     

    Last edit: msuspartan 2013-11-26
  • LogMANOriginal

    LogMANOriginal - 2018-12-08
    • status: open --> closed
    • assigned_to: LogMANOriginal
     
  • LogMANOriginal

    LogMANOriginal - 2018-12-08

    Thanks for reporting this issue! It was fixed a long time ago, so this works in the latest version. I've added a unit test to monitor this behavior in the future [0c97b8]

     

    Related

    Commit: [0c97b8]


Log in to post a comment.