1
0
Fork 0

[react]: fix: Escape user-provided text in SVG. Closes #260

This commit is contained in:
joostdecock 2025-05-01 16:26:09 +02:00 committed by Joost De Cock
parent d0cebc8959
commit d267c04286
2 changed files with 20 additions and 3 deletions

View file

@ -62,6 +62,22 @@ export function clone(obj) {
return JSON.parse(JSON.stringify(obj))
}
/**
* A method to escapte test that needs to be included in the SVG
*
* This is for user-provided text, such as the measrements set name
*
* @param {string} text - Text to escape
* @return {string} escaped - The escapted text
*/
export function escapeSvgText(text) {
return String(text)
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;')
}
/*
* Returns the URL of a user avatar (on cloudflare)
* based on the ihash and Variant