Skip to content

Conversation

@bep
Copy link
Member

@bep bep commented Oct 22, 2025

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

@bep bep requested a review from Copilot October 22, 2025 15:46
Copy link

Copilot AI left a 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 ConvertIfPossible function 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.

@bep bep force-pushed the fix/yamladddate-14079 branch 2 times, most recently from 375e371 to 8869792 Compare October 22, 2025 17:41
bep added 2 commits October 22, 2025 20:11
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
@bep bep force-pushed the fix/yamladddate-14079 branch from 8869792 to bea3721 Compare October 22, 2025 18:11
@bep bep requested a review from Copilot October 22, 2025 18:51
Copy link

Copilot AI left a 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" }}|
Copy link

Copilot AI Oct 22, 2025

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'.

Copilot uses AI. Check for mistakes.
So the example mentioned in #14079 also works for TOML and JSON front matter.

See #14079
@bep bep force-pushed the fix/yamladddate-14079 branch from bea3721 to 5bf6454 Compare October 22, 2025 18:59
@bep bep merged commit e08278d into master Oct 22, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants