fix(#3840): reject a malformed feature order instead of coercing it (#3851)

* fix(#3840): reject a malformed feature `order` instead of coercing it

`scripts/gen-features.cjs` was the one field validated by coercion rather than
by shape. `Number('')` is 0, and `0x10`, `0b11`, `0o17`, `1e3`, `1.` and `.5`
all coerce to finite numbers, so a fragment declaring a bare `order:` sorted to
position 0 -- ahead of every real feature, in both the body and the generated
table of contents -- with zero violations, a clean `--check` and `--write`
exiting 0. That is a fail-open in a gate whose entire contract is a typed
violation rather than a silent guess.

`order` is now shape-checked against an optionally-signed decimal literal
before coercion, mirroring how ID_RE guards `id`. The finite check stays: the
regex alone would admit a literal long enough to overflow to Infinity.

Surfaced by re-running the feature-implementation directive's design and QA
steps against the code merged in #3845, which shipped without them.

Refs #3840

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore(#3840): backfill changeset PR number

Refs #3840

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: sim <sim@local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-08-25 08:36:33 -04:00
committed by GitHub
parent fb2d122d7f
commit 308c17505c
4 changed files with 205 additions and 3 deletions

View File

@@ -361,7 +361,13 @@ shared file, so there is nothing to collide on.
`docs/features/_groups/<slug>.md`, which a feature PR never touches.
4. **`order` is optional.** It defaults to the numeric part of `id`, which is
right for almost everything. Declare it only to place a section somewhere its
number would not put it (`27b` precedes `27a` for historical reasons).
number would not put it (`27b` precedes `27a` for historical reasons). When
declared it must be an optionally-signed integer or decimal — `27`, `0`,
`-1`, `+3`, `27.2`. Anything else is an `order_invalid` violation, including
an empty value, a hex/binary/octal literal and exponential notation: all of
those coerce to a finite number under JavaScript's `Number()`, so before
#3840 a bare `order:` sorted the section to position 0 — ahead of every real
feature — with no violation and a clean `--check`.
5. **Bodies start at `####`.** A `##` or `###` inside a fragment body would
forge a group or a sibling section with no id and no TOC entry; `--check`
rejects it (`body_heading_too_shallow`).