RegEx overlay drops lookaround markers when every match is zero-width #1037

Closed
opened 2026-08-13 05:06:24 +00:00 by spikerj · 1 comment
Owner

In reg-ex.component.ts buildHighlightedTextSegments, zero-width matches (lookaheads/lookbehinds) are supposed to render as a single-space match marker after the breakpoint sweep.

That append runs after if (ranges.length === 0) return [{ text, cssClass: "" }]. Positive-length matches skip len === 0 when building ranges, and empty hint spans are also skipped. So a pattern like (?=a) against "a" produces no ranges, hits the early return, and never paints the lookaround marker.

The marker does appear when mixed with a positive-length match (the early return is skipped).

Fix: run the zero-width append before the empty-ranges return, or don't return early when matches.some(m => m.length === 0).

Found by Wave 7 coverage (agent a8) — characterization test in reg-ex.lessons.spec.ts.

In `reg-ex.component.ts` `buildHighlightedTextSegments`, zero-width matches (lookaheads/lookbehinds) are supposed to render as a single-space `match` marker after the breakpoint sweep. That append runs **after** `if (ranges.length === 0) return [{ text, cssClass: "" }]`. Positive-length matches skip `len === 0` when building `ranges`, and empty hint spans are also skipped. So a pattern like `(?=a)` against `"a"` produces **no ranges**, hits the early return, and never paints the lookaround marker. The marker **does** appear when mixed with a positive-length match (the early return is skipped). **Fix:** run the zero-width append before the empty-ranges return, or don't return early when `matches.some(m => m.length === 0)`. Found by Wave 7 coverage (agent a8) — characterization test in `reg-ex.lessons.spec.ts`.
Author
Owner

Resolved in spikersoft-angular PR #819 (merged to master). RegEx overlay keeps lookaround markers when every match is zero-width. Closing.

Resolved in spikersoft-angular [PR #819](https://git.spikersoft.com/spikerj/spikersoft-angular/pulls/819) (merged to `master`). RegEx overlay keeps lookaround markers when every match is zero-width. Closing.
Sign in to join this conversation.