mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-09-13 20:12:06 +09:00
c1ad057db8
Pasting a link builds the preview by interpolating the unfurled metadata into an HTML string. The image URL went into src="..." unescaped, so a page whose og:image carries a double quote closes the attribute early and everything after it becomes attributes on the preview's img element. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186eyzivcTn6wqjEE4Wnxdt
14 lines
416 B
JavaScript
14 lines
416 B
JavaScript
const HTML_ESCAPES = { "&": "&", "<": "<", ">": ">", "\"": """, "'": "'" }
|
|
|
|
export function truncateString(string, length, omission = "…") {
|
|
if (string.length <= length) {
|
|
return string
|
|
} else {
|
|
return string.slice(0, length - omission.length) + omission
|
|
}
|
|
}
|
|
|
|
export function escapeHTML(string) {
|
|
return String(string).replace(/[&<>"']/g, character => HTML_ESCAPES[character])
|
|
}
|