Skip to content

Commit

Permalink
#2209 Combining sanitasion approaches
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Jul 29, 2021
1 parent 52b1b23 commit 69a1bb9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
14 changes: 4 additions & 10 deletions cypress/platform/knsv.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,11 @@

end
</div>
<div class="mermaid3" style="width: 100%; height: 20%;">
stateDiagram-v2
state CompositeState {
state AnotherCompositeState1234567890 {
YourState
}
}

</div>
&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29
<div class="mermaid" style="width: 100%; height: 20%;">
graph TD
A["<img src=`https://via.placeholder.com/64/`>"]
</div>
<div class="mermaid2" style="width: 100%; height: 20%;">
flowchart TD
Link --> b
click Link href "&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29" "Tooltip for
Expand Down
30 changes: 29 additions & 1 deletion src/diagrams/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,36 @@ export const removeScript = (txt) => {
return rs;
};

const sanitizeMore = (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, '&lt;').replace(/>/g, '&gt;');
txt = txt.replace(/=/g, '&equals;');
txt = placeholderToBreak(txt);
}
}

return txt;
};

export const sanitizeText = (text) => {
const txt = DOMPurify.sanitize(text);
const txt = sanitizeMore(DOMPurify.sanitize(text));

return txt;
};

Expand Down

0 comments on commit 69a1bb9

Please sign in to comment.