Repository navigation
Commit 8cb32e7
fix(core): drop unusable submatches instead of records; bound submatch text
Third review round — one finding from cubic, two from the codex reviewer Ralph
triggered on the PR. All three validated before acting.
- The `startsWith` guard on rebased offsets had an aliasing blind spot. When an
invalid byte precedes a LITERAL U+FFFD, an offset inside that character still
produces a decoded prefix that prefixes the line, because the replacement
characters are indistinguishable — `[ff ef bf bd]` accepts offset 2 and rebases
it to 6. Replaced with byte-boundary validation, which has no such blind spot.
Measured over 3.4M fuzzed offsets against the definition (decoding both halves
must reconstruct the whole): zero unsafe offsets accepted. It errs only
conservatively, on lines beginning mid-sequence.
- An offset that cannot be rebased now drops ITS SUBMATCH rather than the whole
record. The file, line and text are still correct and useful, and losing a
highlight range beats losing the match — which is what this branch exists to
stop. Applies to out-of-range and fractional offsets too.
- Bound the retained submatch text. A broad pattern such as `x.*` makes ripgrep
repeat nearly the whole line in `submatches[].match.text`, so capping only
`lines.text` left the retained-memory bound defeated by the submatches
instead.
- `parseRecords` is namespace-private again. packages/opencode/AGENTS.md
requires namespace-private helpers to be non-exported top-level declarations,
and it had been exported solely so tests could reach it. The legacy tests now
drive the public `search()` against a stub `rg` on PATH, which covers the same
skip branches without widening the public API.
Tests: 21 core, 8 legacy. The four core cases and one legacy case covering the
new behaviour were confirmed to fail against the previous commit. Full core
suite diffed against a freshly built origin/main worktree: 26 failures on both,
none introduced.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>1 parent 7eb9528 commit 8cb32e7
4 files changed
Lines changed: 175 additions & 160 deletions
File tree
- packages
- core
- src
- test
- opencode
- src/file
- test/file
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
159 | 155 | | |
160 | 156 | | |
161 | 157 | | |
| |||
167 | 163 | | |
168 | 164 | | |
169 | 165 | | |
170 | | - | |
171 | | - | |
| 166 | + | |
| 167 | + | |
172 | 168 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
180 | 178 | | |
181 | 179 | | |
182 | 180 | | |
183 | 181 | | |
184 | | - | |
| 182 | + | |
185 | 183 | | |
186 | 184 | | |
187 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
315 | | - | |
| 315 | + | |
| 316 | + | |
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
319 | | - | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | | - | |
326 | 325 | | |
327 | 326 | | |
328 | 327 | | |
329 | | - | |
330 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
337 | 338 | | |
338 | 339 | | |
339 | 340 | | |
340 | | - | |
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
346 | 345 | | |
347 | 346 | | |
348 | 347 | | |
349 | | - | |
350 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
351 | 382 | | |
352 | 383 | | |
353 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
164 | 156 | | |
165 | 157 | | |
166 | 158 | | |
| |||
175 | 167 | | |
176 | 168 | | |
177 | 169 | | |
178 | | - | |
179 | | - | |
| 170 | + | |
| 171 | + | |
180 | 172 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
188 | 178 | | |
189 | 179 | | |
190 | 180 | | |
191 | 181 | | |
192 | 182 | | |
193 | | - | |
| 183 | + | |
194 | 184 | | |
195 | 185 | | |
196 | 186 | | |
| |||
199 | 189 | | |
200 | 190 | | |
201 | 191 | | |
202 | | - | |
| 192 | + | |
| 193 | + | |
203 | 194 | | |
204 | | - | |
| 195 | + | |
205 | 196 | | |
206 | 197 | | |
207 | 198 | | |
| |||
0 commit comments