Skip to content

Problem handling invalid HTML attributes #859

Open
@ZachSaucier

Description

@ZachSaucier

I recently started using Readability.js for a reader view that I work on. One user reported an error with this website (note: it's paywalled so only a limited number of people can view it). The error shown in the console is:

Error handling response: Error: Failed to execute 'setAttribute' on 'Element': '@click' is not a valid attribute name.
    at Readability._simplifyNestedElements

This points to this part of Readability.js:

} else if (
  this._hasSingleTagInsideElement(node, "DIV") ||
  this._hasSingleTagInsideElement(node, "SECTION")
) {
  var child = node.children[0];
    for (var i = 0; i < node.attributes.length; i++) {
      child.setAttribute(
        node.attributes[i].name,
        node.attributes[i].value
      );
    }

I think @click as an attribute is a Vue.js thing.

Regardless, can Readability.js be updated to properly handle (probably just ignore) invalid HTML attributes instead of breaking? I can see validation of attribute names as a way forward or try/catching it and ignoring bits that error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions