File tree Expand file tree Collapse file tree
packages/mermaid/src/diagrams/block Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' mermaid ' : patch
3+ ---
4+
5+ fix(block-beta): respect current DOMPurify config when sanitizing labels
Original file line number Diff line number Diff line change 11import { clone } from 'es-toolkit/compat' ;
22import * as configApi from '../../config.js' ;
3- import { getConfig } from '../../diagram-api/diagramAPI.js' ;
43import type { DiagramDB } from '../../diagram-api/types.js' ;
54import { log } from '../../logger.js' ;
65import common from '../common/common.js' ;
@@ -16,13 +15,11 @@ const COLOR_KEYWORD = 'color';
1615const FILL_KEYWORD = 'fill' ;
1716const BG_FILL = 'bgFill' ;
1817const STYLECLASS_SEP = ',' ;
19- const config = getConfig ( ) ;
18+ const sanitizeText = ( txt : string ) => common . sanitizeText ( txt , configApi . getConfig ( ) ) ;
2019
2120let classes = new Map < string , ClassDef > ( ) ;
2221let diagramId = '' ;
2322
24- const sanitizeText = ( txt : string ) => common . sanitizeText ( txt , config ) ;
25-
2623/**
2724 * Called when the parser comes across a (style) class definition
2825 * @example classDef my-style fill:#f96;
Original file line number Diff line number Diff line change 11// @ts -ignore: jison doesn't export types
22import block from './block.jison' ;
33import db from '../blockDB.js' ;
4+ import * as configApi from '../../../config.js' ;
45import { log } from '../../../logger.js' ;
56
67describe ( 'Block diagram' , function ( ) {
78 describe ( 'when parsing a block diagram graph it should handle > ' , function ( ) {
89 beforeEach ( function ( ) {
10+ configApi . setSiteConfig ( { } ) ;
11+ configApi . reset ( ) ;
912 block . parser . yy = db ;
1013 block . parser . yy . clear ( ) ;
1114 block . parser . yy . getLogger = ( ) => console ;
@@ -34,6 +37,16 @@ describe('Block diagram', function () {
3437 expect ( blocks [ 0 ] . label ) . toBe ( 'A label' ) ;
3538 expect ( blocks [ 0 ] . type ) . toBe ( 'square' ) ;
3639 } ) ;
40+ it ( 'sanitizes labels with the current dompurify config' , ( ) => {
41+ configApi . setSiteConfig ( { dompurifyConfig : { FORBID_TAGS : [ 'b' ] } } ) ;
42+ const str = `block
43+ id["<b>Bold</b>"]
44+ ` ;
45+
46+ block . parse ( str ) ;
47+ const blocks = db . getBlocks ( ) ;
48+ expect ( blocks [ 0 ] . label ) . toBe ( 'Bold' ) ;
49+ } ) ;
3750 it ( 'a diagram with multiple nodes' , ( ) => {
3851 const str = `block
3952 id1
You can’t perform that action at this time.
0 commit comments