Skip to content

Remove javascript event handlers from elements #4333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions packages/readabilityjs/Readability.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Readability.prototype = {

if (!this._keepClasses) {
// Remove classes.
this._cleanClasses(articleContent);
this._cleanElement(articleContent);
}
},

Expand Down Expand Up @@ -456,7 +456,7 @@ Readability.prototype = {
* @param Element
* @return void
*/
_cleanClasses: function (node) {
_cleanElement: function (node) {
if (node.className && node.className.startsWith && node.className.startsWith('_omnivore')) {
return;
}
Expand All @@ -483,8 +483,10 @@ Readability.prototype = {
node.removeAttribute("class");
}

this._removeAllEventHandlers(node)

for (node = node.firstElementChild; node; node = node.nextElementSibling) {
this._cleanClasses(node);
this._cleanElement(node);
}
},

Expand Down Expand Up @@ -546,7 +548,6 @@ Readability.prototype = {
this._forEachNode(medias, function (media) {
var src = media.getAttribute("src");
var poster = media.getAttribute("poster");
var srcset = media.getAttribute("srcset");

if (src) {
media.setAttribute("src", this.toAbsoluteURI(src));
Expand All @@ -558,6 +559,20 @@ Readability.prototype = {
});
},

// removes all the javascript event handlers from the supplied element
_removeAllEventHandlers(element) {
const attributes = element.attributes;

// Iterate in reverse because removing attributes changes the length
for (let i = attributes.length - 1; i >= 0; i--) {
const attribute = attributes[i];
// Check if the attribute starts with "on" (like "onload", "onerror", etc.)
if (attribute.name.startsWith('on')) {
element.removeAttribute(attribute.name);
}
}
},

/** Creates imageproxy links for all article images with href source */
_createImageProxyLinks: function (articleContent) {
if (this.createImageProxyUrl !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2> 途虎养车港交所挂牌 腾讯为最大外部股东 <img src="https://f
<p> 国内汽车服务市场高度分散,2022年,途虎养车取得汽车服务收入115亿元,市场份额0.9% </p>
</div>
<div id="Main_Content_Val">
<p>   <b>【财新网】</b>9月26日,汽车服务平台<a href="https://s.ccxe.com.cn/entities/companies/202035144" target="_blank">途虎养车</a>正式在港交所主板挂牌上市。途虎养车( <a onclick="return false" href="http://fakehost/test/09690.HKM">09690.HK</a> )上市发行价为28港元/股,此前公司披露的发行价区间为28港元/股至31港元/股,即实际发行价为区间下限。当日,途虎养车收报29.5港元/股,较发行价涨5.36%,市值为239.6亿港元。 </p>
<p>   <b>【财新网】</b>9月26日,汽车服务平台<a href="https://s.ccxe.com.cn/entities/companies/202035144" target="_blank">途虎养车</a>正式在港交所主板挂牌上市。途虎养车( <a href="http://fakehost/test/09690.HKM">09690.HK</a> )上市发行价为28港元/股,此前公司披露的发行价区间为28港元/股至31港元/股,即实际发行价为区间下限。当日,途虎养车收报29.5港元/股,较发行价涨5.36%,市值为239.6亿港元。 </p>
<p>   途虎养车上市不易。途虎养车2022年1月即在港交所递表,2022年8月、2023年3月两次重新递交上市申请材料,终于在2023年8月23日通过聆讯。 </p>
</div>
<!--杂志购买 begin-->
Expand Down
Loading
Loading