From afb9d2760f3e1dc99d0244c162f8d0fce9192b7a Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Tue, 17 Mar 2026 22:17:31 +0100 Subject: [PATCH] fix: use search_from offset in indexOf to correctly locate duplicate style blocks --- src/lib/remap-html.test.ts | 14 ++++++++++++++ src/lib/remap-html.ts | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lib/remap-html.test.ts b/src/lib/remap-html.test.ts index cf5bc16..38e0dca 100644 --- a/src/lib/remap-html.test.ts +++ b/src/lib/remap-html.test.ts @@ -44,6 +44,20 @@ test('remaps a single style block', () => { }) }) +test('remaps correctly when two style blocks have identical content', () => { + let css = `h1 { color: red; }` + // Two style tags with identical CSS — indexOf always finds the first occurrence, + // so a range inside the second block falls outside [first_start, first_end] and gets dropped + let html = `` + let second_start = html.lastIndexOf('