From ad7158c315c40e8b1b52798187b924a745fb7460 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 28 Jul 2024 09:57:18 +0300 Subject: [PATCH] chore(utils): add function to sanitise title prop --- packages/utils/package.json | 5 +++++ packages/utils/src/index.ts | 1 + packages/utils/src/misc/title.ts | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 packages/utils/src/misc/title.ts diff --git a/packages/utils/package.json b/packages/utils/package.json index ed25874..0e245d3 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -337,6 +337,11 @@ "require": "./lib/misc/strings.cjs", "import": "./lib/misc/strings.mjs" }, + "./lib/misc/title": { + "types": "./lib/misc/title.d.ts", + "require": "./lib/misc/title.cjs", + "import": "./lib/misc/title.mjs" + }, "./lib/misc/licenses": { "types": "./lib/misc/licenses.d.ts", "require": "./lib/misc/licenses.cjs", diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index e8fb4cb..3c6281d 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -131,3 +131,4 @@ export { compareObjects, unmergeObjects, } from './misc/objects'; +export { sanitiseTitleAttribute } from './misc/title'; diff --git a/packages/utils/src/misc/title.ts b/packages/utils/src/misc/title.ts new file mode 100644 index 0000000..88caead --- /dev/null +++ b/packages/utils/src/misc/title.ts @@ -0,0 +1,8 @@ +/** + * Sanitises title, removing any unwanted characters that might break XML. + * + * This is a very basic funciton, not full parser. + */ +export function sanitiseTitleAttribute(content: string): string { + return content.replace(/[<>&]+/g, ''); +}