[react]: fix: Escape user-provided text in SVG. Closes #260
This commit is contained in:
parent
d0cebc8959
commit
d267c04286
2 changed files with 20 additions and 3 deletions
|
@ -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, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the URL of a user avatar (on cloudflare)
|
||||
* based on the ihash and Variant
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue