Skip to content

Commit

Permalink
make sanitizer to allow svg in process to fix missing text bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Jan 16, 2024
1 parent e6b50ab commit 6a7f9e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion teammapper-frontend/mmp/src/map/handlers/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export default class Export {
const splittedText = fo.firstChild.textContent.split('\n')
// line breaks are created via tspan elements that are relatively positioned using dy property
const svgTextWithLineBreaks = splittedText.map((text, i) => `<tspan dy="${(i === 0 || i === splittedText.length - 1) ? '0' : '1.2em'}" x="${x}">${text}</tspan>`)
const textSVG = DOMPurify.sanitize(svgTextWithLineBreaks.join(''), { USE_PROFILES: { svg: true }, NAMESPACE: 'http://www.w3.org/2000/svg'})
console.log(textSVG)
d3.select(parent)
.attr('width', fo.getAttribute('width'))
.append('text')
Expand All @@ -145,7 +147,7 @@ export default class Export {
.attr('font-family', (fo.firstElementChild as HTMLElement).style.fontFamily)
.attr('font-size', (fo.firstElementChild as HTMLElement).style.fontSize)
.attr('fill', (fo.firstElementChild as HTMLElement).style.color)
.html(DOMPurify.sanitize(svgTextWithLineBreaks.join('')))
.html(textSVG)
fo.remove()
})

Expand Down
14 changes: 10 additions & 4 deletions teammapper-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion teammapper-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@ngx-translate/http-loader": "^7.0.0",
"angular2-hotkeys": "^13.1.0",
"d3": "7.6.1",
"dompurify": "2.4.0",
"dompurify": "3.0.6",
"eslint-config-standard": "^17.0.0",
"jspdf": "^2.5.1",
"localforage": "1.10.0",
Expand Down

0 comments on commit 6a7f9e7

Please sign in to comment.