Skip to content

fix(html): emit lengths the core parser can read - #253

Closed
LeadcodeDev wants to merge 1 commit into
fix/html-unknown-attributesfrom
fix/html-shorthand-lengths
Closed

LeadcodeDev wants to merge 1 commit into
fix/html-unknown-attributesfrom
fix/html-shorthand-lengths

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Severity Medium, category coherence. Location: crates/rustmotion-html/src/style.rs:46

Impact

Two parsers for the same syntax have drifted. Executed: style="padding: 24px 48px; margin: 0 auto; grid-template-columns: repeat(3, 1fr)" transpiles to "padding":"24px 48px", "margin":"0 auto", "grid-template-columns":["repeat(3,","1fr)"]. All three deserialize successfully — Edges::Uniform(LengthPercentage::String) and GridTrack::Length(LengthPercentage::String) are untagged string variants — and then core's parse_length (rustmotion-core/src/css/units.rs:125) only understands a single number+unit token, so parse_length_or_warn (units.rs:262) falls back to Px(0.0): zero padding, zero margin, two zero-width grid tracks. The only signal is an eprintln! warning; validate exits 0 and the render is wrong. Per-side padding is entirely unexpressible from HTML (padding-top:32 is rejected by CssStyle's deny_unknown_fields, padding:32px 48px silently becomes 0), and the skill rule html-css-mental-model.md:97 only documents the JSON object form, which inline style="" cannot produce.

Fix

Teach parse_inline_style the standard 1/2/3/4-value box shorthands for padding/margin/border-radius, emitting the Edges/BorderRadius object the core expects, and teach the grid branch repeat()/minmax(); for anything still multi-token, return a named HtmlError rather than an opaque string. Long term, expose the core's parse_length from rustmotion-core and call it here so one grammar governs both front-ends.

Evidence the audit read

if prop == "grid-template-columns" || prop == "grid-template-rows" {
            let arr: Vec<Value> = value
                .split_whitespace()
                .map(|t| Value::from(t.to_string()))
                .collect();
            map.insert(prop, Value::Array(arr));
        } else {
            map.insert(prop, coerce_value(value));   // multi-token value -> opaque String
        }

Stacked on fix/html-unknown-attributes, which carries the previous finding of this workstream. GitHub shows only this finding's diff; merge in order.

Part of the September 2026 audit remediation chantier. Refs #220 (RM-04).

@LeadcodeDev LeadcodeDev added the bug Something isn't working label Sep 21, 2026
@LeadcodeDev LeadcodeDev self-assigned this Sep 21, 2026
@LeadcodeDev
LeadcodeDev force-pushed the fix/html-unknown-attributes branch from cf25e25 to 122c9ec Compare September 22, 2026 06:11
@LeadcodeDev
LeadcodeDev force-pushed the fix/html-shorthand-lengths branch from 342377a to c0d2efd Compare September 22, 2026 06:11
@LeadcodeDev
LeadcodeDev force-pushed the fix/html-unknown-attributes branch from 122c9ec to 838dc53 Compare September 22, 2026 08:35
@LeadcodeDev
LeadcodeDev force-pushed the fix/html-shorthand-lengths branch from c0d2efd to f36abbf Compare September 22, 2026 08:35
@LeadcodeDev
LeadcodeDev force-pushed the fix/html-unknown-attributes branch from 838dc53 to 6b6c8d9 Compare September 22, 2026 08:45
Two parsers for the same syntax have drifted. Executed: style="padding: 24px
48px; margin: 0 auto; grid-template-columns: repeat(3, 1fr)" transpiles to
"padding":"24px 48px", "margin":"0 auto", "grid-template-
columns":["repeat(3,","1fr)"]. All three deserialize successfully —
Edges::Uniform(LengthPercentage::String) and
GridTrack::Length(LengthPercentage::String) are untagged string variants —
and then core's parse_length (rustmotion-core/src/css/units.rs:125) only
understands a single number+unit token, so parse_length_or_warn
(units.rs:262) falls back to Px(0.0): zero padding, zero margin, two zero-
width grid tracks. The only signal is an eprintln! warning; validate exits 0
and the render is wrong. Per-side padding is entirely unexpressible from
HTML (padding-top:32 is rejected by CssStyle's deny_unknown_fields,
padding:32px 48px silently becomes 0), and the skill rule html-css-mental-
model.md:97 only documents the JSON object form, which inline style=""
cannot produce.

Fix: Teach parse_inline_style the standard 1/2/3/4-value box shorthands for
padding/margin/border-radius, emitting the Edges/BorderRadius object the
core expects, and teach the grid branch repeat()/minmax(); for anything
still multi-token, return a named HtmlError rather than an opaque string.
Long term, expose the core's parse_length from rustmotion-core and call it
here so one grammar governs both front-ends.

Refs #220
@LeadcodeDev
LeadcodeDev force-pushed the fix/html-shorthand-lengths branch from f36abbf to 895d8e3 Compare September 22, 2026 08:45
@LeadcodeDev
LeadcodeDev deleted the branch fix/html-unknown-attributes September 22, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant