Skip to content

Commit 4cee519

Browse files
authored
Merge pull request #54 from cloudoptlab/feat-2.x-dompurify
Feat 2.x dompurify
2 parents d6c6dbb + cff31d5 commit 4cee519

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

manifest.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@
6969
},
7070
{
7171
"all_frames": true,
72-
"js": ["adguard/adguard-content.js"],
72+
"js": [
73+
"lib/purify.min.js",
74+
"adguard/adguard-content.js"
75+
],
7376
"matches": [
7477
"http://*/*",
7578
"https://*/*"
@@ -82,7 +85,10 @@
8285
"css": [
8386
"adguard/assistant/css/selector.css"
8487
],
85-
"js": ["adguard/adguard-assistant.js"],
88+
"js": [
89+
"lib/purify.min.js",
90+
"adguard/adguard-assistant.js"
91+
],
8692
"matches": [
8793
"http://*/*",
8894
"https://*/*"

src/adguard/adguard-assistant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@
27152715

27162716
$.i = function(s, context) {
27172717
fn.push.apply(this, !s ? fn : s.nodeType || s == window ? [s] : "" + s === s ? /</.test(s) ?
2718-
((i = document.createElement(context || 'q')).innerHTML = s, i.children) : (context && $(context)[0] || document).querySelectorAll(s) : /f/.test(typeof s) ? /c/.test(document.readyState) ? s() : $(document).on('DOMContentLoaded', s) : s);
2718+
((i = document.createElement(context || 'q')).innerHTML = DOMPurify.sanitize(s), i.children) : (context && $(context)[0] || document).querySelectorAll(s) : /f/.test(typeof s) ? /c/.test(document.readyState) ? s() : $(document).on('DOMContentLoaded', s) : s);
27192719
};
27202720

27212721
$.i[l = 'prototype'] = ($.extend = function(obj) {

src/adguard/adguard-content.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,9 +1556,9 @@ setDocument = Sizzle.setDocument = function( node ) {
15561556
// setting a boolean content attribute,
15571557
// since its presence should be enough
15581558
// https://bugs.jquery.com/ticket/12359
1559-
docElem.appendChild( el ).innerHTML = "<a id='" + expando + "'></a>" +
1559+
docElem.appendChild( el ).innerHTML = DOMPurify.sanitize("<a id='" + expando + "'></a>" +
15601560
"<select id='" + expando + "-\r\\' msallowcapture=''>" +
1561-
"<option selected=''></option></select>";
1561+
"<option selected=''></option></select>");
15621562

15631563
// Support: IE8, Opera 11-12.16
15641564
// Nothing should be selected when empty strings follow ^= or $= or *=
@@ -1595,8 +1595,8 @@ setDocument = Sizzle.setDocument = function( node ) {
15951595
});
15961596

15971597
assert(function( el ) {
1598-
el.innerHTML = "<a href='' disabled='disabled'></a>" +
1599-
"<select disabled='disabled'><option/></select>";
1598+
el.innerHTML = DOMPurify.sanitize("<a href='' disabled='disabled'></a>" +
1599+
"<select disabled='disabled'><option/></select>");
16001600

16011601
// Support: Windows 8 Native Apps
16021602
// The type and name attributes are restricted during .innerHTML assignment
@@ -3021,7 +3021,7 @@ support.sortDetached = assert(function( el ) {
30213021
// Prevent attribute/property "interpolation"
30223022
// https://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
30233023
if ( !assert(function( el ) {
3024-
el.innerHTML = "<a href='#'></a>";
3024+
el.innerHTML = DOMPurify.sanitize("<a href='#'></a>");
30253025
return el.firstChild.getAttribute("href") === "#" ;
30263026
}) ) {
30273027
addHandle( "type|href|height|width", function( elem, name, isXML ) {
@@ -3034,7 +3034,7 @@ if ( !assert(function( el ) {
30343034
// Support: IE<9
30353035
// Use defaultValue in place of getAttribute("value")
30363036
if ( !support.attributes || !assert(function( el ) {
3037-
el.innerHTML = "<input/>";
3037+
el.innerHTML = DOMPurify.sanitize("<input/>");
30383038
el.firstChild.setAttribute( "value", "" );
30393039
return el.firstChild.getAttribute( "value" ) === "";
30403040
}) ) {
@@ -5273,4 +5273,4 @@ var initPageMessageListener = function () { // jshint ignore:line
52735273
init();
52745274
})();
52755275

5276-
})(window);
5276+
})(window);

src/guide/guide.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ export class GuideManager {
5050
}
5151

5252
private setHeader(headerElement: HTMLElement) {
53-
this.mainDOM.querySelector('#contentBlock .header').innerHTML = ''
53+
this.mainDOM.querySelector('#contentBlock .header').innerHTML = rtpl.render(' ', null)
5454
this.mainDOM.querySelector('#contentBlock .header').appendChild(headerElement)
5555
}
5656

5757
private setFooter(footerElement: HTMLElement) {
58-
this.mainDOM.querySelector('#contentBlock .footer').innerHTML = ''
58+
this.mainDOM.querySelector('#contentBlock .footer').innerHTML = rtpl.render(' ', null)
5959
this.mainDOM.querySelector('#contentBlock .footer').appendChild(footerElement)
6060
}
6161

6262
private setBody(bodyElement: HTMLElement) {
63-
this.mainDOM.querySelector('#contentBlock .body').innerHTML = ''
63+
this.mainDOM.querySelector('#contentBlock .body').innerHTML = rtpl.render(' ', null)
6464
this.mainDOM.querySelector('#contentBlock .body').appendChild(bodyElement)
6565
}
6666

src/option/routerManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import AboutUsPages from './component/aboutUs'
66
import { TOptionsType } from './component/userAside'
77
import { IBaseHTMLPages } from './component/types'
88
import { get as getCoreConfig, set as setCoreConfig } from '../core/config'
9+
import rtpl from 'art-template/lib/template-web.js'
910

1011
export default class RouterManager {
1112
private static ID: string = 'routerAside'
@@ -18,7 +19,7 @@ export default class RouterManager {
1819

1920
constructor() {
2021
this.mainDOM.id = RouterManager.ID
21-
this.mainDOM.innerHTML = '<div />'
22+
this.mainDOM.innerHTML = rtpl.render('<div />')
2223
}
2324

2425
public async renderByType(type: TOptionsType): Promise<void> {

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module.exports = {
7676
{ from: "node_modules/popper.js/dist/umd/popper.min.js", to: "lib/" },
7777
{ from: "node_modules/@antv/g2/dist/g2.min.js", to: "lib/g2/" },
7878
{ from: "node_modules/@antv/data-set/dist/data-set.min.js", to: "lib/g2/" },
79+
{ from: "node_modules/dompurify/dist/purify.min.js", to: "lib/purify.min.js" },
7980
{ from: "src/libs/icon", to: "lib/icon" },
8081
{ from: "css", to: "css" },
8182
{ from: "_locales", to: "_locales" },

0 commit comments

Comments
 (0)