mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(tools): bound untrusted display text at output boundaries
This commit is contained in:
1 parent
de2138e84c
commit
586ed4f8ea
9 files changed
+106
-17
No files matched your search
@@ -0,0 +1,12 @@
|
||||
/** Bounded, single-line external display text; it remains untrusted source data. */
|
||||
export function normalizeDisplayText(value, maxLength = 180) {
|
||||
if (value == null || typeof value === 'object' || typeof value === 'function')
|
||||
return '';
|
||||
return String(value)
|
||||
.replace(/[\u0000-\u001f\u007f-\u009f]/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
.slice(0, maxLength)
|
||||
.replace(/[\uD800-\uDBFF]$/, '')
|
||||
.trim();
|
||||
}
|
||||
Reference in new issue
Block a user