mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-26 10:49:38 +02:00
Merge branch 'develop' into fix/entity-decode
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
export const getRows = s => {
|
||||
if (!s) return 1;
|
||||
let str = breakToPlaceholder(s);
|
||||
@@ -27,36 +29,15 @@ export const removeScript = txt => {
|
||||
}
|
||||
}
|
||||
|
||||
rs = rs.replace('javascript:', '#');
|
||||
rs = rs.replace('<iframe', '');
|
||||
rs = rs.replace(/javascript:/g, '#');
|
||||
rs = rs.replace(/onerror=/g, 'onerror:');
|
||||
rs = rs.replace(/<iframe/g, '');
|
||||
|
||||
return rs;
|
||||
};
|
||||
|
||||
export const sanitizeText = (text, config) => {
|
||||
let txt = text;
|
||||
let htmlLabels = true;
|
||||
if (
|
||||
config.flowchart &&
|
||||
(config.flowchart.htmlLabels === false || config.flowchart.htmlLabels === 'false')
|
||||
) {
|
||||
htmlLabels = false;
|
||||
}
|
||||
|
||||
if (htmlLabels) {
|
||||
const level = config.securityLevel;
|
||||
|
||||
if (level === 'antiscript') {
|
||||
txt = removeScript(txt);
|
||||
} else if (level !== 'loose') {
|
||||
// eslint-disable-line
|
||||
txt = breakToPlaceholder(txt);
|
||||
txt = txt.replace(/</g, '<').replace(/>/g, '>');
|
||||
txt = txt.replace(/=/g, '=');
|
||||
txt = placeholderToBreak(txt);
|
||||
}
|
||||
}
|
||||
|
||||
export const sanitizeText = text => {
|
||||
const txt = DOMPurify.sanitize(text);
|
||||
return txt;
|
||||
};
|
||||
|
||||
@@ -74,10 +55,6 @@ const breakToPlaceholder = s => {
|
||||
return s.replace(lineBreakRegex, '#br#');
|
||||
};
|
||||
|
||||
const placeholderToBreak = s => {
|
||||
return s.replace(/#br#/g, '<br/>');
|
||||
};
|
||||
|
||||
const getUrl = useAbsolute => {
|
||||
let url = '';
|
||||
if (useAbsolute) {
|
||||
|
File diff suppressed because one or more lines are too long
@@ -121,7 +121,7 @@ describe('[Singlenodes] when parsing', () => {
|
||||
|
||||
expect(edges.length).toBe(0);
|
||||
expect(vert['a'].type).toBe('diamond');
|
||||
expect(vert['a'].text).toBe('A <br/> end');
|
||||
expect(vert['a'].text).toBe('A <br> end');
|
||||
});
|
||||
|
||||
it('should handle a single hexagon node', function() {
|
||||
@@ -144,7 +144,7 @@ describe('[Singlenodes] when parsing', () => {
|
||||
|
||||
expect(edges.length).toBe(0);
|
||||
expect(vert['a'].type).toBe('hexagon');
|
||||
expect(vert['a'].text).toBe('A <br/> end');
|
||||
expect(vert['a'].text).toBe('A <br> end');
|
||||
});
|
||||
|
||||
it('should handle a single round node with html in it', function() {
|
||||
@@ -156,7 +156,7 @@ describe('[Singlenodes] when parsing', () => {
|
||||
|
||||
expect(edges.length).toBe(0);
|
||||
expect(vert['a'].type).toBe('round');
|
||||
expect(vert['a'].text).toBe('A <br/> end');
|
||||
expect(vert['a'].text).toBe('A <br> end');
|
||||
});
|
||||
|
||||
it('should handle a single node with alphanumerics starting on a char', function() {
|
||||
|
@@ -328,7 +328,7 @@ describe('[Text] when parsing', () => {
|
||||
const edges = flow.parser.yy.getEdges();
|
||||
|
||||
expect(vert['C'].type).toBe('round');
|
||||
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br/> - ÅÄÖ');
|
||||
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ');
|
||||
});
|
||||
// xit('it should handle åäö, minus and space and br',function(){
|
||||
// const res = flow.parser.parse('graph TD; A[Object(foo,bar)]-->B(Thing);');
|
||||
|
@@ -101,13 +101,14 @@ describe('when parsing ', function() {
|
||||
charTest('<', '<');
|
||||
});
|
||||
|
||||
it("it should be able to parse a '>'", function() {
|
||||
charTest('>', '>');
|
||||
});
|
||||
// it("it should be able to parse a '>'", function() {
|
||||
// charTest('>', '>');
|
||||
// });
|
||||
|
||||
it("it should be able to parse a '='", function() {
|
||||
charTest('=', '=');
|
||||
});
|
||||
|
||||
// it("it should be able to parse a '='", function() {
|
||||
// charTest('=', '=');
|
||||
// });
|
||||
it("it should be able to parse a '&'", function() {
|
||||
charTest('&');
|
||||
});
|
||||
|
Reference in New Issue
Block a user