fix: cast whole-number floats to int in argument validation - #358
Merged
Conversation
Data that round-trips through JSON delivers every number as float64 — notably page frontmatter injected by CloudCannon's visual editor (Bookshop live rendering). Int-typed arguments such as cols, padding, width, and limit then failed the type check with 'expected type int, got float64' even though the YAML source declares plain integers, breaking live preview for any component with an int argument. Cast float values with no fractional part losslessly to int, mirroring the existing string-to-int casting; fractional values still fail the type check. Adds whole-float and fractional-float golden cases. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
🎉 This PR is included in version 6.8.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In CloudCannon's visual editor, Bookshop live rendering injects the edited page's frontmatter into the embedded Hugo engine after a JSON round-trip — and JSON has no integer type, so every number arrives as float64. The v6 validation engine then rejects int-typed arguments with hard errors:
Observed on a production site's visual editor after upgrading to the v3 generation: every component with an int argument (
cols,padding,width,limit,heading.size, …) fails to render in live preview with "Build failed: logged N error(s)", while CLI builds of the identical content pass — YAML parses those values as real ints, so the mismatch only appears in the live-editing path.Fix
Extend the casting block in
Args.html(which already casts"42"→ int and scalars → string): a float value with no fractional part whose argument acceptsintbut notfloatis cast losslessly to int. Fractional values (42.5) still fail the type check as before. Float-typed arguments are unaffected (they already accept int input, and float stays float).Tests
castinggroup:whole-float-to-int(42.0 → 42, no error) andfractional-float-to-int(42.5 → type error preserved).npm test: golden check passed (14 groups); all existing goldens byte-identical.🤖 Generated with Claude Code