fix: avoid infinite recursion when formatting ranges as short npm

TryFormat for the "ns" format returned false for any set that can
not be expressed as a caret/tilde range. The public ToString
routes through DefaultInterpolatedStringHandler, whose buffer-full
fallback re-enters ToString, causing an infinite loop / stack overflow.

For "ns", fall back to the full comparator ("n") form when the
compact form cannot represent the set, so the call always succeeds
for a representable range. A genuine buffer overflow still returns
false as before.

Add failing-then-passing tests.
This commit is contained in:
Louis Seubert 2026-07-11 21:57:23 +02:00
commit ae2163188f
3 changed files with 34 additions and 1 deletions

View file

@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Reject invalid SemVer identifiers when parsing versions.
- Range exact and non-equal comparators ignore build metadata when matching versions.
- Avoid infinite recursion when formatting ranges in the short npm (`ns`) form.
### Removed