Skip to content

Commit

Permalink
Merge pull request #764 from openstad/hotfix/resource-form-trim-descr…
Browse files Browse the repository at this point in the history
…iption

chore: Filter out unicode text
  • Loading branch information
iandebruin98 authored Feb 18, 2025
2 parents e7a021a + c82310b commit e20b01a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/api-server/src/util/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@ const removeEmojis = (text) => {
return !!text ? text.replace(/\p{Emoji}/gu, '') : text;
};

const normalizeUnicodeText = (text) => {
if (!text) return text;

return text.replace(/\uD835[\uDC00-\uDFFF]/g, char => {
const code = char.codePointAt(0);

if (code >= 0x1D400 && code <= 0x1D7FF) {
return String.fromCharCode(code - 0x1D400 + 65);
}

return char;
});
}

// Decorator for the sanitize function
// This prevents the bug where sanitize returns the string 'null' when null is passed
const sanitizeIfNotNull = (text, tags) => {
if (text === null) {
return null;
}
text = removeEmojis(text);
text = normalizeUnicodeText(text);
return sanitize(text, tags);
}

Expand Down

0 comments on commit e20b01a

Please sign in to comment.