Skip to content

Commit

Permalink
Avoid setAttribute errors from invalid attributes, fixes mozilla#392
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsk authored and 1257mp committed Jul 19, 2019
1 parent 5754f43 commit c4113e1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,16 @@ Readability.prototype = {
replacement.readability = node.readability;

for (var i = 0; i < node.attributes.length; i++) {
replacement.setAttribute(node.attributes[i].name, node.attributes[i].value);
try {
replacement.setAttribute(node.attributes[i].name, node.attributes[i].value);
} catch (ex) {
/* it's possible for setAttribute() to throw if the attribute name
* isn't a valid XML Name. Such attributes can however be parsed from
* source in HTML docs, see https://github.com/whatwg/html/issues/4275,
* so we can hit them here and then throw. We don't care about such
* attributes so we ignore them.
*/
}
}
return replacement;
},
Expand Down

0 comments on commit c4113e1

Please sign in to comment.