Skip to content

fix: cast whole-number floats to int in argument validation - #358

Merged
markdumay merged 1 commit into
mainfrom
fix/int-accepts-whole-float
Jul 28, 2026
Merged

fix: cast whole-number floats to int in argument validation#358
markdumay merged 1 commit into
mainfrom
fix/int-accepts-whole-float

Conversation

@markdumay

Copy link
Copy Markdown
Collaborator

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:

ERROR partial [assets/stack.html] - Invalid arguments:
  [stack] argument 'cols': expected type 'int', got 'float64' with value '4'

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 accepts int but not float is 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

  • New golden cases in the casting group: whole-float-to-int (42.0 → 42, no error) and fractional-float-to-int (42.5 → type error preserved).
  • npm test: golden check passed (14 groups); all existing goldens byte-identical.

🤖 Generated with Claude Code

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>
@markdumay
markdumay merged commit e39bb81 into main Jul 28, 2026
11 checks passed
@markdumay
markdumay deleted the fix/int-accepts-whole-float branch July 28, 2026 11:46
@markdumay

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 6.8.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant