Skip to content

Commit 22eb363

Browse files
CopilotAarebecca
andauthored
fix: move empty id check before visited set, add parentheses for operator precedence
- Move !id guard before visited.add() to prevent empty strings being added - Add parentheses around range checks in CSS escape fallback for correct precedence Agent-Logs-Url: https://github.com/antvis/Infographic/sessions/289607cf-6b2e-4c1c-b79d-ec538a1b098c Co-authored-by: Aarebecca <25787943+Aarebecca@users.noreply.github.com>
1 parent 70471bf commit 22eb363

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/exporter/svg.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,10 @@ function collectDefElements(svg: SVGSVGElement, ids: Set<string>) {
489489

490490
while (queue.length) {
491491
const id = queue.shift()!;
492+
if (!id) continue;
492493
if (visited.has(id)) continue;
493494
visited.add(id);
494495

495-
if (!id) {
496-
continue;
497-
}
498-
499496
const selector = `#${escapeCssId(id)}`;
500497
const target = svg.querySelector(selector);
501498
if (!target) continue;
@@ -567,9 +564,9 @@ function escapeCssId(id: string) {
567564

568565
// Characters that are safe to use unescaped
569566
if (
570-
codeUnit >= 0x0030 && codeUnit <= 0x0039 || // 0-9
571-
codeUnit >= 0x0041 && codeUnit <= 0x005a || // A-Z
572-
codeUnit >= 0x0061 && codeUnit <= 0x007a || // a-z
567+
(codeUnit >= 0x0030 && codeUnit <= 0x0039) || // 0-9
568+
(codeUnit >= 0x0041 && codeUnit <= 0x005a) || // A-Z
569+
(codeUnit >= 0x0061 && codeUnit <= 0x007a) || // a-z
573570
codeUnit === 0x002d || // -
574571
codeUnit === 0x005f // _
575572
) {

0 commit comments

Comments
 (0)