#901 Fixed the issue with multiple calls to bind the click functions. Also sanitized the tooltips so that no tags are allowed in them for (#847).

This commit is contained in:
knsv
2019-08-11 03:26:44 -07:00
parent a6f21c2b91
commit 7b335fb62e
5 changed files with 41 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ let funs = []
const sanitize = text => {
let txt = text
if (config.securityLevel === 'strict') {
if (config.securityLevel !== 'loose') {
txt = txt.replace(/<br>/g, '#br#')
txt = txt.replace(/<br\S*?\/>/g, '#br#')
txt = txt.replace(/</g, '&lt;').replace(/>/g, '&gt;')
@@ -182,13 +182,13 @@ export const setClass = function (ids, className) {
const setTooltip = function (ids, tooltip) {
ids.split(',').forEach(function (id) {
if (typeof tooltip !== 'undefined') {
tooltips[id] = tooltip
tooltips[id] = sanitize(tooltip)
}
})
}
const setClickFun = function (id, functionName) {
if (config.securityLevel === 'strict') {
if (config.securityLevel !== 'loose') {
return
}
if (typeof functionName === 'undefined') {
@@ -215,7 +215,7 @@ const setClickFun = function (id, functionName) {
export const setLink = function (ids, linkStr, tooltip) {
ids.split(',').forEach(function (id) {
if (typeof vertices[id] !== 'undefined') {
if (config.securityLevel === 'strict') {
if (config.securityLevel !== 'loose') {
vertices[id].link = sanitizeUrl(linkStr) // .replace(/javascript:.*/g, '')
} else {
vertices[id].link = linkStr

View File

@@ -228,6 +228,7 @@ export const addEdges = function (edges, g) {
* @returns {object} classDef styles
*/
export const getClasses = function (text) {
logger.info('Extracting classes')
flowDb.clear()
const parser = flow.parser
parser.yy = flowDb
@@ -243,7 +244,7 @@ export const getClasses = function (text) {
* @param id
*/
export const draw = function (text, id) {
logger.debug('Drawing flowchart')
logger.info('Drawing flowchart')
flowDb.clear()
const parser = flow.parser
parser.yy = flowDb

View File

@@ -430,7 +430,7 @@ const compileTasks = function () {
*/
export const setLink = function (ids, _linkStr) {
let linkStr = _linkStr
if (config.securityLevel === 'strict') {
if (config.securityLevel !== 'loose') {
linkStr = sanitizeUrl(_linkStr)
}
ids.split(',').forEach(function (id) {
@@ -457,7 +457,7 @@ export const setClass = function (ids, className) {
}
const setClickFun = function (id, functionName, functionArgs) {
if (config.securityLevel === 'strict') {
if (config.securityLevel !== 'loose') {
return
}
if (typeof functionName === 'undefined') {

View File

@@ -497,10 +497,17 @@ const render = function (id, txt, cb, container) {
svgCode = decodeEntities(svgCode)
if (typeof cb !== 'undefined') {
cb(svgCode, flowDb.bindFunctions)
cb(svgCode, ganttDb.bindFunctions)
switch(graphType) {
case 'flowchart':
cb(svgCode, flowDb.bindFunctions)
break;
case 'gantt':
cb(svgCode, ganttDb.bindFunctions)
break;
default:
}
} else {
logger.warn('CB = undefined!')
logger.debug('CB = undefined!')
}
const node = d3.select('#d' + id).node()