Refuse a measurement that makes the label stop existing
Some checks failed
CI / backend (push) Failing after 7m11s
CI / naming (push) Failing after 7m10s
CI / frontend (push) Failing after 7m18s
CI / migrations-mysql (push) Failing after 7m5s

Reported as a barcode rendering 176 by 0. A bar height of zero is what does it:
the number went straight into a CSS length, height: 0in is perfectly valid, and
an image sized height: 100% of a zero-height box is zero pixels tall. The label
comes out full width with nothing on it, which reads as a rendering failure
rather than as a field doing exactly what it was told.

A cleared field was the same bug wearing a different hat. An emptied number
input holds '', not 0, so the page emitted `NaNin`; the browser dropped the
declaration and the box fell back to auto height. That one merely looked wrong
instead of vanishing, which is arguably worse for finding it.

Measurements now go through labelVars(), which will not emit NaN, an empty
length, or a zero for anything whose zero means the box stops existing. Padding,
the quiet zone and the gap still take zero, because there zero is a real answer,
and offsets stay signed. It is a separate module because this is exactly the
kind of arithmetic that needs tests rather than a preview: every case in
labelVars.spec.js is a value a number input can actually hold.

The stylesheet now carries fallbacks on its var() reads as well, but they are a
net, not the fix: a custom property set to garbage is substituted and then
dropped at computed value time, and the fallback does not apply - it only covers
a property that is absent entirely.
This commit is contained in:
cproudlock
2026-08-21 12:09:26 -04:00
parent 3703412baf
commit f09d14d28c
4 changed files with 214 additions and 44 deletions

View File

@@ -51,6 +51,18 @@ ADR-007 and ADR-002.
### Fixed
- **A zero bar height printed a barcode 176 wide and 0 high.** Nothing rejected
it: the value went straight into a CSS length, `height: 0in` is perfectly
valid, and an image at `height: 100%` of a zero-height box is zero pixels
tall. A cleared field was its own version of the same bug - `'' + 'in'` is not
a length, the browser dropped the declaration, and the box fell back to auto
height. Every measurement now goes through `labelVars()`, which will not emit
NaN, an empty length, or a zero where a zero means the box stops existing;
padding, quiet zone and gap still accept zero, because there it is a real
answer. The stylesheet carries its own fallbacks too, though those only cover
a property that is absent - a property set to garbage is dropped at computed
value time and takes the fallback with it, which is why the sanitiser is the
fix and the CSS is only a net.
- **A caption could eat the barcode.** The code box and the caption both grew,
so any caption took half the label and kept going: "BAY 12 PRESS LINE 1" on
1.00 x 0.50in stock left a 36px stub, which is a code that is present,