Commit ac94ad4
authored
fix(fetchers): avoid utf-8 panic in hn html stripping (#115)
Iterate `strip_html_tags` input with `char_indices()` and compute the `<p>`-lookahead slice from `idx + c.len_utf8()` instead of `html.len() - (html.len() - result.len())`, which dropped UTF-8 byte alignment when non-ASCII characters had been skipped from `result`. Prevents a panic on untrusted HN item/comment text.1 parent e95d349 commit ac94ad4
1 file changed
Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
| 323 | + | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
| 328 | + | |
332 | 329 | | |
333 | 330 | | |
334 | 331 | | |
| |||
393 | 390 | | |
394 | 391 | | |
395 | 392 | | |
| 393 | + | |
396 | 394 | | |
397 | 395 | | |
398 | 396 | | |
| |||
0 commit comments