Skip to content

fix(decoder): Correctly unmarshal !!int tagged values#770

Open
rybakit wants to merge 1 commit intogoccy:masterfrom
rybakit:fix-decoder-int-tag
Open

fix(decoder): Correctly unmarshal !!int tagged values#770
rybakit wants to merge 1 commit intogoccy:masterfrom
rybakit:fix-decoder-int-tag

Conversation

@rybakit
Copy link

@rybakit rybakit commented Jun 24, 2025

This PR fixes the unmarshaling logic to properly handle YAML values with explicit !!int tags. For example:

var data map[string]int
err := yaml.Unmarshal([]byte("a: !!int 42"), &data)

Error returned:

Failed to process YAML: [1:4] cannot unmarshal int into Go value of type int
        >  1 | a: !!int 42
                  ^

@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 39.28571% with 17 lines in your changes missing coverage. Please review.

Project coverage is 77.83%. Comparing base (25e5d90) to head (3b2de25).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #770      +/-   ##
==========================================
- Coverage   77.97%   77.83%   -0.14%     
==========================================
  Files          22       22              
  Lines        8108     8134      +26     
==========================================
+ Hits         6322     6331       +9     
- Misses       1370     1387      +17     
  Partials      416      416              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 the unmarshaling logic for YAML values with explicit !!int tags by introducing a new castToInt helper function that properly handles type conversions from various integer types and strings to int64/uint64.

  • Replaces the previous strconv.Atoi(fmt.Sprint(v)) approach with a more robust type-switching conversion
  • Adds comprehensive test coverage for integer tag handling including quoted strings and various numeric formats
  • Updates float tag tests to use map[string]float64 instead of map[string]interface{} for consistency

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
decode.go Adds castToInt function to properly handle type conversions for !!int tagged values, replacing the previous string-based conversion approach
decode_test.go Adds test cases for various !!int tagged formats (quoted strings, hex, octal) and updates existing !!float tests for type consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants