From 21f3db152fdae5e4a22cc3984cc0936212ee9702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanna=20Torm=C3=A4hlen?= Date: Fri, 3 Jan 2025 16:07:11 +0100 Subject: [PATCH] #171 -- in story doesnt break the svg export anymore --- src/app/tools/export/services/svg.service.ts | 6 +++- .../labeling/dsLabelEditingProvider.js | 7 ++++- .../headlineAndDescriptionUpdateHandler.js | 6 ++-- src/app/utils/sanitizer.spec.ts | 31 +++++++++++++++++-- src/app/utils/sanitizer.ts | 9 +++++- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/app/tools/export/services/svg.service.ts b/src/app/tools/export/services/svg.service.ts index e12621b4..8d898e47 100644 --- a/src/app/tools/export/services/svg.service.ts +++ b/src/app/tools/export/services/svg.service.ts @@ -8,6 +8,7 @@ import { } from '../domain/export/exportConstants'; import { StoryCreatorService } from '../../replay/services/story-creator.service'; import { StorySentence } from '../../replay/domain/storySentence'; +import { sanitizeTextForSVGExport } from 'src/app/utils/sanitizer'; @Injectable({ providedIn: 'root', @@ -216,7 +217,10 @@ export class SvgService { } private appendDST(data: string, dst: ConfigAndDST): string { - data += '\n'; + data += + '\n'; return data; } } diff --git a/src/app/tools/modeler/bpmn/modeler/labeling/dsLabelEditingProvider.js b/src/app/tools/modeler/bpmn/modeler/labeling/dsLabelEditingProvider.js index 9307545a..e34dfe1e 100644 --- a/src/app/tools/modeler/bpmn/modeler/labeling/dsLabelEditingProvider.js +++ b/src/app/tools/modeler/bpmn/modeler/labeling/dsLabelEditingProvider.js @@ -5,6 +5,7 @@ import { assign } from "min-dash"; import { autocomplete, getLabel } from "./dsLabelUtil"; import { ElementTypes } from "src/app/domain/entities/elementTypes"; +import { sanitizeTextForSVGExport } from "src/app/utils/sanitizer"; import { is } from "../util"; let dictionaryService; @@ -307,5 +308,9 @@ DSLabelEditingProvider.prototype.update = function ( }; } - this._modeling.updateLabel(element, newLabel, newBounds); + this._modeling.updateLabel( + element, + sanitizeTextForSVGExport(newLabel), + newBounds, + ); }; diff --git a/src/app/tools/modeler/bpmn/modeler/updateHandler/headlineAndDescriptionUpdateHandler.js b/src/app/tools/modeler/bpmn/modeler/updateHandler/headlineAndDescriptionUpdateHandler.js index 7f4fd9fd..83912f16 100644 --- a/src/app/tools/modeler/bpmn/modeler/updateHandler/headlineAndDescriptionUpdateHandler.js +++ b/src/app/tools/modeler/bpmn/modeler/updateHandler/headlineAndDescriptionUpdateHandler.js @@ -1,3 +1,5 @@ +import { sanitizeTextForSVGExport } from "src/app/utils/sanitizer"; + export default function headlineAndDescriptionUpdateHandler( commandStack, titleService, @@ -13,8 +15,8 @@ export default function headlineAndDescriptionUpdateHandler( ctx.oldDescription = titleService.getDescription(); titleService.updateTitleAndDescription( - ctx.newTitle, - ctx.newDescription, + sanitizeTextForSVGExport(ctx.newTitle), + sanitizeTextForSVGExport(ctx.newDescription), false, ); }; diff --git a/src/app/utils/sanitizer.spec.ts b/src/app/utils/sanitizer.spec.ts index a6b37277..932fb283 100644 --- a/src/app/utils/sanitizer.spec.ts +++ b/src/app/utils/sanitizer.spec.ts @@ -1,10 +1,35 @@ -import { sanitizeForDesktop, sanitizeIconName } from './sanitizer'; +import { + sanitizeForDesktop, + sanitizeIconName, + sanitizeTextForSVGExport, +} from './sanitizer'; describe('sanitizer', () => { + describe('sanitize for SVG Export', () => { + it('should not sanitize', () => { + const unsanitized = '-test-'; + expect(sanitizeTextForSVGExport(unsanitized)).toEqual('-test-'); + }); + }); + + describe('sanitize for SVG Export', () => { + it('should sanitize', () => { + const unsanitized = '-test--'; + expect(sanitizeTextForSVGExport(unsanitized)).toEqual('-test––'); + }); + }); + + describe('sanitize for SVG Export', () => { + it('should sanitize multiple times', () => { + const unsanitized = '------'; + expect(sanitizeTextForSVGExport(unsanitized)).toEqual('––––––'); + }); + }); + describe('sanitize for desktop', () => { it('should sanitize', () => { - const unsanitized = '/\\:*?"><|test'; - expect(sanitizeForDesktop(unsanitized)).toEqual('test'); + const unsanitized = '/\\:*?"><|-test--'; + expect(sanitizeForDesktop(unsanitized)).toEqual('-test––'); }); }); diff --git a/src/app/utils/sanitizer.ts b/src/app/utils/sanitizer.ts index 2f541437..2547968f 100644 --- a/src/app/utils/sanitizer.ts +++ b/src/app/utils/sanitizer.ts @@ -1,5 +1,10 @@ 'use strict'; +export function sanitizeTextForSVGExport(str: string): string { + // @ts-ignore Typescript does not realize that replaceAll exists, no idea why not. + return str.replaceAll('--', '––'); +} + // sanitize user-Input to be Desktop-Filename safe export function sanitizeForDesktop(str: string): string { const map: { [key: string]: string } = { @@ -14,7 +19,9 @@ export function sanitizeForDesktop(str: string): string { '|': '', }; const reg = /[/\\:*?"<>|]/gi; - return str ? str.replace(reg, (match) => map[match]) : ''; + return str + ? sanitizeTextForSVGExport(str.replace(reg, (match) => map[match])) + : ''; } export function sanitizeIconName(name: string): string {