Skip to content

Commit

Permalink
Merge pull request #26 from loadchange/escape-special-chars
Browse files Browse the repository at this point in the history
Escape special characters in Canvas mode
  • Loading branch information
loadchange authored May 15, 2024
2 parents ac32b76 + 5b301ff commit 0b9355c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ class CanvasWay {
this.canvas.setAttribute('height', `${ height }`);
}

private escapeSpecialCharacters(txt: string): string {
return txt.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

public render(): string {
const { txt, x, y, width, height, font, color, fontSize, alpha, angle } = this.watermark;
const { x, y, width, height, font, color, fontSize, alpha, angle } = this.watermark;
const txt = this.escapeSpecialCharacters(this.watermark.txt);
const ctx = this.canvas.getContext('2d');
if (ctx === null) {
throw new Error('getContext error');
Expand Down

0 comments on commit 0b9355c

Please sign in to comment.