Fix map marker photos: escapeCssUrl no longer encodes the letter "s"

The character class /['"()\s<>]/ matched a backslash and the letter "s"
instead of whitespace, so every "s" in a marker image URL became %73
(https:// -> http%73://). The colored circles still rendered, but the
background-image URL was broken. Use \\s (backslash + whitespace).

Add tests: escapeCssUrl keeps a presigned URL intact and still encodes
backslash/whitespace; MapView puts the original imageUrl into the marker
template.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-21 22:51:36 +03:00
parent f25d034cad
commit bfc9a1bd1d
3 changed files with 35 additions and 1 deletions

View File

@@ -18,9 +18,13 @@ export function escapeHtml(value) {
/**
* URL для CSS url('...') внутри HTML-атрибута style: кавычки, скобки и
* обратный слэш процентно кодируются, чтобы значение не вышло за пределы url().
*
* В классе символов `\\` — это обратный слэш, а `\s` — пробельные символы.
* Раньше там стояло `\\s`, то есть «слэш и буква s»: каждая s в URL
* превращалась в %73 (https:// → http%73://), и фото в маркерах карты пропадали.
*/
export function escapeCssUrl(value) {
return String(value ?? "").replace(/['"()\\s<>]/g, (ch) =>
return String(value ?? "").replace(/['"()\\\s<>]/g, (ch) =>
`%${ch.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`
);
}

View File

@@ -35,6 +35,15 @@ describe("escapeHtml", () => {
it("URL не выходит за пределы url('...')", () => {
expect(escapeCssUrl("a.jpg');background:url('x")).not.toMatch(/['()]/);
});
it("обычный presigned URL не меняется (буква s не кодируется)", () => {
const url = "https://s3.example.com/bucket/a.jpg?X-Amz-Signature=abc&presigned=true";
expect(escapeCssUrl(url)).toBe(url);
});
it("кодирует обратный слэш и пробельные символы", () => {
expect(escapeCssUrl("a\\b c\nd")).toBe("a%5Cb%20c%0Ad");
});
});
describe("validatePassword", () => {