Repository navigation
Fix implicit null converted to empty string in flow mappings - #331
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #320
Summary
Fixes an issue where implicit null scalars within flow mappings (such as
a: {b: }or GitHub Actions workflow dispatch blockson: { push: { branches: [main] }, workflow_dispatch: }) were converted into empty single-quoted strings''(e.g.a: {b: ''}).Root Cause
In
pkg/yaml/emitterc.go, an empty scalar node was marked withflow_plain_allowed = falseandlen == 0 && emitter.flow_level > 0unconditionally forcedstyle = yaml_SINGLE_QUOTED_SCALAR_STYLE. This caused implicit null values in flow mappings to fall back to single-quoted empty strings''.Changes
emitter.scalar_data.flow_plain_allowed = truefor empty scalar values inyaml_emitter_analyze_scalar.yaml_emitter_select_scalar_stylefromlen(value) == 0 && (emitter.flow_level > 0 || emitter.simple_key_context)to only checklen(value) == 0 && emitter.simple_key_context.stripTrailingNewlineinformatter_test.goto properly strip CRLF endings.pkg/yaml/node_test.go(TestFlowMappingImplicitNull) andformatters/basic/formatter_test.go.