Skip to content

Commit

Permalink
Merge pull request #6 from mermaid-js/develop
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
jgreywolf authored Dec 9, 2019
2 parents 91d9869 + 08cbc0f commit cf5d747
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ categories:
change-template: '- $TITLE (#$NUMBER) @$AUTHOR'
branches:
- develop
exclude-labels:
- 'Skip changelog'
no-changes-template: 'This release contains minor changes and bugfixes.'
template: |
# Release Notes
Expand Down
21 changes: 20 additions & 1 deletion cypress/integration/other/xss.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,27 @@ describe('XSS', () => {
const url = mermaidUrl(str,{}, true);

cy.visit(url);
cy.wait(1000).then(()=>{
cy.get('.mermaid').should('exist');
});
cy.get('svg')
cy.percySnapshot()
// cy.percySnapshot()

})
it('should handle xss in tags in non-html mode', () => {
const str = 'eyJjb2RlIjoiXG5ncmFwaCBMUlxuICAgICAgQi0tPkQoPGltZyBvbmVycm9yPWxvY2F0aW9uPWBqYXZhc2NyaXB0XFx1MDAzYXhzc0F0dGFja1xcdTAwMjhkb2N1bWVudC5kb21haW5cXHUwMDI5YCBzcmM9eD4pOyIsIm1lcm1haWQiOnsidGhlbWUiOiJkZWZhdWx0IiwiZmxvd2NoYXJ0Ijp7Imh0bWxMYWJlbHMiOmZhbHNlfX19';

const url = mermaidUrl(str,{
"theme": "default",
"flowchart": {
"htmlMode": false
}
}, true);

cy.visit(url);
// cy.get('svg')
// cy.percySnapshot()
cy.get('.malware').should('not.exist');

})
})
32 changes: 16 additions & 16 deletions cypress/integration/rendering/gitGraph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import { imgSnapshotTest } from '../../helpers/util.js';

describe('Sequencediagram', () => {
it('should render a simple git graph', () => {
imgSnapshotTest(
`
gitGraph:
commit
branch newbranch
checkout newbranch
commit
commit
checkout master
commit
commit
merge newbranch`,
{ logLevel: 0 }
);
});
// it('should render a simple git graph', () => {
// imgSnapshotTest(
// `
// gitGraph:
// commit
// branch newbranch
// checkout newbranch
// commit
// commit
// checkout master
// commit
// commit
// merge newbranch`,
// { logLevel: 0 }
// );
// });
});
26 changes: 15 additions & 11 deletions cypress/platform/current.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@
href="https://fonts.googleapis.com/css?family=Montserrat&display=swap"
rel="stylesheet"
/>
<style>
body {background: black}
h1 { color: white;}
.arrowheadPath {fill: red;}

.edgePath .path {stroke: red;}


</style>
</head>
<body>
<h1>info below</h1>
<div style="display: flex;">
<div class="mermaid">stateDiagram
[*] --> State1
State1 --> State2 : Transition 1
State1 --> State3 : Transition 2
State1 --> State4 : Transition 3
State1 --> State5 : Transition 4
State2 --> State3 : Transition 5
State1 --> [*]
<div class="mermaid">graph TD
A ==> B
A --> C
A -.-> D
</div>
</div>
<script src="./mermaid.js"></script>
<script>
mermaid.initialize({
theme: 'forest',
theme: 'dark',
// arrowMarkerAbsolute: true,
// themeCSS: '.node rect { fill: red; }',
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
logLevel: 3,
flowchart: { curve: 'linear' },
flowchart: { curve: 'linear', "htmlLabels": false },
gantt: { axisFormat: '%m/%d/%Y' },
sequence: { actorMargin: 50 },
// sequenceDiagram: { actorMargin: 300 } // deprecated
Expand Down
6 changes: 3 additions & 3 deletions cypress/platform/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const contentLoaded = function() {
document.getElementsByTagName('body')[0].appendChild(div);
}
global.mermaid.initialize(graphObj.mermaid);
// console.log('graphObj.mermaid', graphObj.mermaid)
global.mermaid.init();
}
};
Expand All @@ -55,7 +54,7 @@ const contentLoadedApi = function() {
divs[i] = div;
}

global.mermaid.initialize(graphObj.mermaid);
mermaid2.initialize(graphObj.mermaid);

for (let i = 0; i < numCodes; i++) {
mermaid2.render(
Expand All @@ -74,8 +73,9 @@ const contentLoadedApi = function() {
div.id = 'block';
div.className = 'mermaid';
// div.innerHTML = graphObj.code
console.warn('graphObj.mermaid', graphObj.mermaid);
document.getElementsByTagName('body')[0].appendChild(div);
global.mermaid.initialize(graphObj.mermaid);
mermaid2.initialize(graphObj.mermaid);

mermaid2.render(
'newid',
Expand Down
5 changes: 4 additions & 1 deletion cypress/platform/xss.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
div.id = 'the-malware'
div.className = 'malware'
div.innerHTML = 'XSS Succeeded'
document.getElementsByTagName('body')[0].appendChild(div)
document.getElementsByTagName('body')[0].appendChild(div);
// const el = document.querySelector('.mermaid');
// el.parentNode.removeChild(el);
throw new Error('XSS Succeded');
}
</script>
</head>
Expand Down
8 changes: 7 additions & 1 deletion src/diagrams/flowchart/flowDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ let funs = [];

const sanitize = text => {
let txt = text;
if (config.securityLevel !== 'loose') {
let htmlLabels = true;
if (
config.flowchart &&
(config.flowchart.htmlLabels === false || config.flowchart.htmlLabels === 'false')
)
htmlLabels = false;
if (config.securityLevel !== 'loose' && htmlLabels) { // eslint-disable-line
txt = txt.replace(/<br>/g, '#br#');
txt = txt.replace(/<br\S*?\/>/g, '#br#');
txt = txt.replace(/</g, '&lt;').replace(/>/g, '&gt;');
Expand Down
4 changes: 2 additions & 2 deletions src/diagrams/flowchart/flowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ export const addEdges = function(edges, g) {
}
break;
case 'dotted':
style = 'stroke: #333; fill:none;stroke-width:2px;stroke-dasharray:3;';
style = 'fill:none;stroke-width:2px;stroke-dasharray:3;';
break;
case 'thick':
style = 'stroke: #333; stroke-width: 3.5px;fill:none';
style = ' stroke-width: 3.5px;fill:none';
break;
}
}
Expand Down

0 comments on commit cf5d747

Please sign in to comment.