Files
Dylan M. Taylor b948ad4674 fix: strip script URL schemes from markdown links; crop before exact-fit resize (#329)
What was wrong:
- simple_markdown_to_html escaped literal HTML but let pulldown-cmark
emit links/images with executable URL schemes (`[x](javascript:...)`,
`data:`, `vbscript:`).
- resize_preserving_aspect(exact_fit=true) used resize_to_fill, which
scales the entire source to cover the target before cropping; an
extreme-aspect source needed a huge intermediate buffer.

Change: link and image destinations whose scheme is not http, https or
mailto are replaced with `#` (scheme-less relative/anchor URLs pass;
control characters and whitespace inside the scheme are ignored when
classifying, as browsers do). Exact-fit now crops the source to the
target aspect ratio first and then resize_exact's the crop, so the
working size is bounded by the target.

Blast radius: crates/lib/markdown (simple_markdown_to_html only) and
crates/lib/files/images.

Behavior changes: links with other schemes (ftp:, tel:, etc.) render as
`#`. Exact-fit output has the same dimensions as before; crop offsets
can differ by a pixel from resize_to_fill's rounding.

Checks run: cargo test -p markdown (36 pass, 2 new); cargo test -p
images --lib resize (8 pass, 1 new with a 4000x1 source).
Checks not run: fmt/clippy; the ml background-removal resize finding
(separate caller bounds) is not addressed here.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Image resizing with exact dimensions now preserves the requested
aspect ratio by cropping the image before resizing. Very thin images are
also handled reliably.
* Markdown links and images now reject unsafe URL schemes, while
standard web and email links continue to work.


<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:17:29 -05:00
..
2025-04-09 20:39:36 -04:00