- changed status to open
Example code
import org.snakeyaml.engine.v2.api.DumpSettings
import org.snakeyaml.engine.v2.api.StreamDataWriter
import org.snakeyaml.engine.v2.common.ScalarStyle
import org.snakeyaml.engine.v2.emitter.Emitter
import org.snakeyaml.engine.v2.events.*
import java.io.StringWriter
import java.util.*
fun main() {
val settings = DumpSettings.builder()
.setWidth(80) // Intentionally limited.
.build()
val writer = object : StringWriter(), StreamDataWriter {
override fun flush() {
// no-op
}
}
val emitter = Emitter(settings, writer)
emitter.emit(StreamStartEvent())
emitter.emit(DocumentStartEvent(false, Optional.empty(), emptyMap()))
val stringToSerialize = "arn:aws:iam::12345678901234567890:foobarbaz:testing:testing2:role/github-actions-role/${'$'}{{ github.token }}"
emitter.emit(ScalarEvent(Optional.empty(), Optional.empty(), ImplicitTuple(true, true), stringToSerialize, ScalarStyle.PLAIN))
emitter.emit(DocumentEndEvent(false))
emitter.emit(StreamEndEvent())
val yaml = writer.toString()
println(yaml)
}
Actual
arn:aws:iam::12345678901234567890:foobarbaz:testing:testing2:role/github-actions-role/${{
github.token }}
Expected
arn:aws:iam::12345678901234567890:foobarbaz:testing:testing2:role/github-actions-role/${{
\ github.token }}
Description
There’s a problem when the line break falls around a place which includes a whitespace. It turned out that in my use cases, this space is important and SnakeYaml produced something equivalent to:
arn:aws:iam::12345678901234567890:foobarbaz:testing:testing2:role/github-actions-role/${{github.token }}
/\
missing space
instead what was expected (see above). The result was that the emitted YAML was incorrectly parsed on the receiver side.
Workaround
I currently configure the dumper to have no line length limit:
val settings = DumpSettings.builder()
// Otherwise line breaks appear in places that create an incorrect YAML, e.g. in the middle of GitHub
// expressions.
.setWidth(Int.MAX_VALUE)
.build()
but I don’t really like it. It would be good to go back to line lengths that can fit on a regular display’s width.
Looks like there is some discrepancy on the GitHub’s side, but TBH, I don’t have resources to chase it down.