Skip to content
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

Handle unmarshall unknown aliases #317

Merged
merged 1 commit into from Oct 26, 2022

Conversation

nervo
Copy link
Contributor

@nervo nervo commented Sep 16, 2022

Right now, trying to unmarshall invalid yaml (with unknown aliases) using custom unmarshallers lead to a panic.

See: https://go.dev/play/p/3DT9zna3Mft

This is due to decode:resolveAlias (resolveAlias) method which could not handle errors, and its AliasNode switch case (

case *ast.AliasNode:
) which don't check the presence of an alias in anchorNodeMap before returning a node.
If an alias is unknown, decode:resolveAlias returns nil, breaking all subsequents handlings.

This pr introduce errors handling in resolveAlias, and its related methods unmarshalableDocument & unmarshalableText. It also checks that an alias is present in the anchorNodeMap an returns error if not.

@codecov-commenter
Copy link

Codecov Report

Merging #317 (ec3ae19) into master (ecececd) will decrease coverage by 0.33%.
The diff coverage is 56.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #317      +/-   ##
==========================================
- Coverage   75.92%   75.58%   -0.34%     
==========================================
  Files          13       13              
  Lines        4299     4350      +51     
==========================================
+ Hits         3264     3288      +24     
- Misses        798      819      +21     
- Partials      237      243       +6     

@nervo nervo force-pushed the handle-unmarshall-unknown-aliases branch from ec3ae19 to 941abdb Compare September 16, 2022 11:16
@goccy
Copy link
Owner

goccy commented Oct 26, 2022

Thank you for the great PR ! LGTM !

@goccy goccy merged commit 8607d4f into goccy:master Oct 26, 2022
@nervo nervo deleted the handle-unmarshall-unknown-aliases branch October 11, 2023 08:59
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.

None yet

3 participants