renamed bleach to remixBleach

pull/5370/head
lianahus 4 years ago committed by Liana Husikyan
parent 4198fdb259
commit 28b8a29ca4
  1. 2
      apps/remix-ide-e2e/src/tests/debugger.test.ts
  2. 4
      apps/remix-ide/src/app/tabs/debugger-tab.js
  3. 99
      apps/remix-ide/src/lib/remixBleach.js

@ -67,7 +67,7 @@ module.exports = {
.click('.ace_gutter-cell:nth-of-type(20)')
.waitForElementVisible('*[data-id="buttonNavigatorJumpPreviousBreakpoint"]')
.click('*[data-id="buttonNavigatorJumpPreviousBreakpoint"]')
.pause(2000)
.pause(5000)
.assert.containsText('*[data-id="stepdetail"]', 'vm trace step:\n0')
.assert.containsText('*[data-id="stepdetail"]', 'execution step:\n0')
.click('*[data-id="buttonNavigatorJumpNextBreakpoint"]')

@ -6,7 +6,7 @@ import * as packageJson from '../../../../../package.json'
import React from 'react' // eslint-disable-line
import ReactDOM from 'react-dom'
import modalDialogCustom from '../ui/modal-dialog-custom'
import * as bleach from '../../lib/bleach'
import * as remixBleach from '../../lib/remixBleach'
const css = require('./styles/debugger-tab-styles')
const yo = require('yo-yo')
@ -65,7 +65,7 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) {
showMessage (title, message) {
try {
modalDialogCustom.alert(title, bleach.sanitize(message))
modalDialogCustom.alert(title, remixBleach.sanitize(message))
} catch (e) {
console.log(e)
}

@ -0,0 +1,99 @@
/*
* remixBleach
* a minimal html sanitizer
* credits to cam@onswipe.com
*/
import * as he from 'he'
const remixBleach = {
matcher: /<\/?([a-zA-Z0-9]+)*(.*?)\/?>/igm,
whitelist: [
'a',
'b',
'p',
'em',
'strong'
],
analyze: function (html) {
html = String(html) || ''
const matches = []
let match
// extract all tags
while ((match = remixBleach.matcher.exec(html)) != null) {
const attrr = match[2].split(' ')
const attrs = []
// extract attributes from the tag
attrr.shift()
attrr.forEach((attr) => {
attr = attr.split('=')
const attrName = attr[0]
let attrValue = attr.length > 1 ? attr.slice(1).join('=') : null
// remove quotes from attributes
if (attrValue && attrValue.charAt(0).match(/'|"/)) attrValue = attrValue.slice(1)
if (attrValue && attrValue.charAt(attrValue.length - 1).match(/'|"/)) attrValue = attrValue.slice(0, -1)
attr = {
name: attrName,
value: attrValue
}
if (!attr.value) delete attr.value
if (attr.name) attrs.push(attr)
})
var tag = {
full: match[0],
name: match[1],
attr: attrs
}
matches.push(tag)
}
return matches
},
sanitize: function (html, options) {
html = String(html) || ''
options = options || {}
const mode = options.mode || 'white'
const list = options.list || remixBleach.whitelist
var matches = remixBleach.analyze(html)
if ((mode === 'white' && list.indexOf('script') === -1) ||
(mode === 'black' && list.indexOf('script') !== -1)) {
html = html.replace(/<script(.*?)>(.*?[\r\n])*?(.*?)(.*?[\r\n])*?<\/script>/gim, '')
}
if ((mode === 'white' && list.indexOf('style') === -1) ||
(mode === 'black' && list.indexOf('style') !== -1)) {
html = html.replace(/<style(.*?)>(.*?[\r\n])*?(.*?)(.*?[\r\n])*?<\/style>/gim, '')
}
matches.forEach(function (tag) {
if (mode === 'white') {
if (list.indexOf(tag.name) === -1) {
html = html.replace(tag.full, '')
}
} else if (mode === 'black') {
if (list.indexOf(tag.name) !== -1) {
html = html.replace(tag.full, '')
}
} else {
throw new Error('Unknown sanitization mode "' + mode + '"')
}
})
if (options.encode_entities) html = he.encode(html)
return html
}
}
module.exports = remixBleach
Loading…
Cancel
Save