Align Sidebar & BottomNav menus, remove "Search", add user profile mock data, implement /api/users, add FilterDrawer, complete Section, ProfileHeader, MetricsRFM components Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
23 lines
700 B
TypeScript
23 lines
700 B
TypeScript
/**
|
|
* 文本清洗工具:去除常见的 JSON 残留与转义符,避免卡片描述中出现 \\n、"]]} 等。
|
|
* - 保持幂等:多次调用不会破坏原文本语义
|
|
* - 安全:不做危险字符拼接或 HTML 注入
|
|
*/
|
|
export function sanitizeText(input?: string): string {
|
|
if (!input) return ""
|
|
let s = String(input)
|
|
|
|
// 1) 常见序列清洗
|
|
s = s.replace(/\\n/g, " ") // 去除转义换行
|
|
s = s.replace(/\s+/g, " ").trim()
|
|
|
|
// 2) 去掉串首尾常见 JSON 残留符号(宽松处理)
|
|
s = s.replace(/^[\s\["'{(\\]+/g, "")
|
|
s = s.replace(/["'\]\})\\\s]+$/g, "")
|
|
|
|
// 3) 反转义常见字符
|
|
s = s.replace(/\\"/g, '"').replace(/\\'/g, "'")
|
|
|
|
return s.trim()
|
|
}
|