This commit is contained in:
kuberwastaken 2026-03-31 16:25:52 +05:30
commit ec53fcbe95
1905 changed files with 513762 additions and 0 deletions

16
utils/xml.ts Normal file
View file

@ -0,0 +1,16 @@
/**
* Escape XML/HTML special characters for safe interpolation into element
* text content (between tags). Use when untrusted strings (process stdout,
* user input, external data) go inside `<tag>${here}</tag>`.
*/
export function escapeXml(s: string): string {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
}
/**
* Escape for interpolation into a double- or single-quoted attribute value:
* `<tag attr="${here}">`. Escapes quotes in addition to `& < >`.
*/
export function escapeXmlAttr(s: string): string {
return escapeXml(s).replace(/"/g, '&quot;').replace(/'/g, '&apos;')
}