From 6a7f9e786106fbf3084deb9ad9fbd4ff7617d42d Mon Sep 17 00:00:00 2001 From: Jannik Streek Date: Tue, 16 Jan 2024 16:04:14 +0100 Subject: [PATCH] make sanitizer to allow svg in process to fix missing text bug --- teammapper-frontend/mmp/src/map/handlers/export.ts | 4 +++- teammapper-frontend/package-lock.json | 14 ++++++++++---- teammapper-frontend/package.json | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/teammapper-frontend/mmp/src/map/handlers/export.ts b/teammapper-frontend/mmp/src/map/handlers/export.ts index c6d741c4..6d2de991 100644 --- a/teammapper-frontend/mmp/src/map/handlers/export.ts +++ b/teammapper-frontend/mmp/src/map/handlers/export.ts @@ -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) => `${text}`) + 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') @@ -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() }) diff --git a/teammapper-frontend/package-lock.json b/teammapper-frontend/package-lock.json index 51365f83..71b7a4a7 100644 --- a/teammapper-frontend/package-lock.json +++ b/teammapper-frontend/package-lock.json @@ -31,7 +31,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", @@ -9525,9 +9525,9 @@ "dev": true }, "node_modules/dompurify": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.0.tgz", - "integrity": "sha512-Be9tbQMZds4a3C6xTmz68NlMfeONA//4dOavl/1rNw50E+/QO0KVpbcU0PcaW0nsQxurXls9ZocqFxk8R2mWEA==" + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.0.6.tgz", + "integrity": "sha512-ilkD8YEnnGh1zJ240uJsW7AzE+2qpbOUYjacomn3AvJ6J4JhKGSZ2nh4wUIXPZrEPppaCLx5jFe8T89Rk8tQ7w==" }, "node_modules/domutils": { "version": "3.0.1", @@ -13651,6 +13651,12 @@ "html2canvas": "^1.0.0-rc.5" } }, + "node_modules/jspdf/node_modules/dompurify": { + "version": "2.4.7", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.7.tgz", + "integrity": "sha512-kxxKlPEDa6Nc5WJi+qRgPbOAbgTpSULL+vI3NUXsZMlkJxTqYI9wg5ZTay2sFrdZRWHPWNi+EdAhcJf81WtoMQ==", + "optional": true + }, "node_modules/jsprim": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", diff --git a/teammapper-frontend/package.json b/teammapper-frontend/package.json index 177d7f6b..c57577ef 100644 --- a/teammapper-frontend/package.json +++ b/teammapper-frontend/package.json @@ -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",