-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix it so YAML integer types can be used where Go int types are expected. #14080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where YAML integer types (specifically uint64) from the goccy/go-yaml library cannot be used where Go int types are expected, such as in time.Time.AddDate(). The fix adds type conversion logic to handle conversions between different integer types (uint to int, int to int) with overflow checking.
- Adds
ConvertIfPossiblefunction to handle safe integer type conversions with overflow detection - Integrates the conversion logic into the template execution engine's type validation
- Adds comprehensive test coverage for the conversion logic and the original issue scenario
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| common/hreflect/helpers.go | Implements ConvertIfPossible function for safe integer type conversions |
| common/hreflect/helpers_test.go | Adds test cases for integer conversion with overflow scenarios |
| tpl/internal/go_templates/texttemplate/hugo_template.go | Adds new validateType method that uses ConvertIfPossible for type validation |
| tpl/internal/go_templates/texttemplate/exec.go | Renames existing validateType to _validateType to avoid conflict |
| tpl/templates/templates_integration_test.go | Adds integration test verifying YAML integers work with AddDate |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
375e371 to
8869792
Compare
E.g. in date.AddDate. In Hugo v0.152.0 we moved to a new YAML library (github.com/goccy/go-yaml) which produces uint64 for unsigned integers. This unfortunately breaks common constructs like: .Date.AddDate 0 0 7 when .Date is a time.Time and the integers are unmarshaled from YAML front matter. This commit adds code to handle conversion from uint64 (and other int types) to the required int types where possible. Fixes #14079
8869792 to
bea3721
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| -- layouts/all.html -- | ||
| {{ $date := "2023-10-15T13:18:50-07:00" | time }} | ||
| {{ $mydata := resources.Get "mydata.yaml" | transform.Unmarshal }} | ||
| date: {{ $date | time.Format "2006-01-06" }}| |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected date format string from '2006-01-06' to '2006-01-02'. The format string uses reference time 'Mon Jan 2 15:04:05 MST 2006' where day is '02', not '06'.
bea3721 to
5bf6454
Compare
E.g. in date.AddDate.
In Hugo v0.152.0 we moved to a new YAML library (github.com/goccy/go-yaml) which produces uint64 for unsigned integers.
This unfortunately breaks common constructs like:
.Date.AddDate 0 0 7
when .Date is a time.Time and the integers are unmarshaled from YAML front matter.
This commit adds code to handle conversion from uint64 (and other int types) to the required int types where possible.
Fixes #14079