Files
nahodka-front/src/utils/escapeHtml.js
SlimusMinus db37befb8d Support new backend contracts: single-flight refresh, ad impression tokens, error handling
- apiFetch: proactive refresh, cross-tab single-flight via Web Locks, no logout on transient errors
- AuthContext: save tokens returned on own login change, revoke refresh on logout, sync tabs
- Ads: X-Session-Id, impressionToken in impression/click, IAB viewability, safe http(s) targetUrl
- STOMP: refresh before CONNECT, stop reconnect loop on dead session, /user/queue/errors behind flag
- Auth form: password 8 chars / 72 bytes; 429/413 messages via describeApiError
- My posts with auth + moderation badges; post form step validation and field limits
- Map: escape user text in Yandex hint/template

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 02:03:42 +03:00

27 lines
964 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const HTML_ESCAPES = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;",
};
/**
* Экранирует текст для вставки в HTML-строку. Нужен там, где разметку
* собирает не React, а сторонняя библиотека (шаблоны и подсказки
* Яндекс.Карт рендерят строку как HTML).
*/
export function escapeHtml(value) {
return String(value ?? "").replace(/[&<>"']/g, (ch) => HTML_ESCAPES[ch]);
}
/**
* URL для CSS url('...') внутри HTML-атрибута style: кавычки, скобки и
* обратный слэш процентно кодируются, чтобы значение не вышло за пределы url().
*/
export function escapeCssUrl(value) {
return String(value ?? "").replace(/['"()\\s<>]/g, (ch) =>
`%${ch.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`
);
}