fix: std.parseYaml preserves trailing newline for clip-chomped block scalars#1028
Merged
stephenamar-db merged 1 commit intoJun 24, 2026
Conversation
be326a2 to
291f22f
Compare
This was referenced Jun 24, 2026
stephenamar-db
approved these changes
Jun 24, 2026
Collaborator
|
please rebase |
adfaa86 to
2b05a0a
Compare
Motivation: SnakeYAML 2.x strips the trailing newline from clip-chomped literal and folded block scalars. std.parseYaml should preserve the YAML default clip chomping behavior on JVM. Modification: Detect JVM SnakeYAML literal/folded scalar nodes, inspect the raw block scalar header for explicit keep/strip chomping indicators, and append the missing trailing newline only for default clip chomping. Header comments are ignored when scanning for chomping indicators, and the JVM-only golden test is skipped on JS/WASM/Native. Result: std.parseYaml now preserves one trailing newline for clip-chomped block scalars while leaving explicit keep/strip chomping unchanged.
2b05a0a to
ec57ec1
Compare
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.
Summary
This PR fixes JVM
std.parseYamlblock scalar clip chomping for literal (|) and folded (>) YAML block scalars.SnakeYAML 2.x strips the trailing newline from default clip-chomped block scalars. YAML clip chomping should preserve exactly one trailing newline when no explicit
+or-chomping indicator is present.Behavior comparison
Local reference versions used:
v0.22.0v0.22.00.5.0-pre99"line1\nline2\n""line1\nline2""line1\nline2""line1\nline2\n\n"a: >\n line1\n line2"line1 line2\n""line1 line2""line1 line2\n""line1\nline2""line1\nline2\n""line1\nline2\n""line1\nline2"The header-comment case follows go-jsonnet, jrsonnet, and YAML comment semantics:
+or-inside a comment must not be interpreted as a chomping indicator. C++ jsonnet differs for that edge case.Changes
Platform.scala(JVM): detect literal/folded SnakeYAML scalar nodes and inspect the raw YAML block scalar header for explicit chomping indicatorsPlatform.scala(JVM): append the missing trailing newline only for default clip chompingPlatform.scala(JVM): stop scanning for chomping indicators at header commentsparseyaml_block_scalar_chomping.jsonnet: golden regression coverage for clip/keep/strip, folded/literal, indentation indicators, blank lines, and header commentsTests
rtk ./mill 'sjsonnet.jvm[3.3.7]'.test.testOnly sjsonnet.ParseYamlTests sjsonnet.FileTests rtk git diff --check upstream/master...HEADBoth passed locally after rebasing onto
upstream/master.