Skip to content

fix(parser): do not panic on empty tagged value under %TAG !! - #988

Open
ump45nose wants to merge 1 commit into
goccy:masterfrom
ump45nose:fix/987-empty-tagged-value-secondary-tag
Open

ump45nose wants to merge 1 commit into
goccy:masterfrom
ump45nose:fix/987-empty-tagged-value-secondary-tag

Conversation

@ump45nose

Copy link
Copy Markdown

Summary

When a document declares %TAG !! … (secondary tag handle), parseTag always built a string node from the token after the tag. If that value is missing at EOF (for example a: !!str or - !!str), ctx.currentToken() is nil and newStringNode panics with a nil pointer dereference.

Without the directive, the same inputs already work: parseTagValue treats a nil token as an implicit null. This change mirrors that handling on the secondary-directive path and leaves the non-nil path unchanged.

Fixes #987

Test plan

  • Added TestIssue987EmptyTaggedValueUnderSecondaryTagDirective covering the three inputs from the issue (mapping, sequence, document-level tag).
  • go test -count=1 -run TestIssue987EmptyTaggedValueUnderSecondaryTagDirective .
  • go test -count=1 -timeout 120s .
  • go test -count=1 ./parser/

When a secondary tag directive is active, parseTag always built a string
node from the token after the tag. At EOF that token is nil, so
newStringNode panicked. Treat a missing value like parseTagValue does and
synthesize an implicit null instead.

Fixes goccy#987
@codecov-commenter

Copy link
Copy Markdown

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

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.67%. Comparing base (edee2f9) to head (4bf770e).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #988      +/-   ##
==========================================
+ Coverage   80.65%   80.67%   +0.01%     
==========================================
  Files          22       22              
  Lines        6845     6851       +6     
==========================================
+ Hits         5521     5527       +6     
  Misses        905      905              
  Partials      419      419              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Parser panics on an empty tagged value under a %TAG !! directive

2 participants