From 0b56a1da2d491a02d3a6125edd19c27416120fd4 Mon Sep 17 00:00:00 2001 From: Tracey Yoshima Date: Wed, 18 Oct 2023 12:40:52 -0600 Subject: [PATCH] Minor fix: added multiline scalar condition back into YamlParser with test. (#3633) fixes #3632 --- .../main/java/org/openrewrite/yaml/YamlParser.java | 3 +++ .../org/openrewrite/yaml/tree/MappingTest.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/rewrite-yaml/src/main/java/org/openrewrite/yaml/YamlParser.java b/rewrite-yaml/src/main/java/org/openrewrite/yaml/YamlParser.java index 6245fcf1799..bd60f386c5b 100644 --- a/rewrite-yaml/src/main/java/org/openrewrite/yaml/YamlParser.java +++ b/rewrite-yaml/src/main/java/org/openrewrite/yaml/YamlParser.java @@ -241,6 +241,9 @@ private Yaml.Documents parseFromInput(Path sourceFile, EncodingDetectingInputStr case PLAIN: default: style = Yaml.Scalar.Style.PLAIN; + if (!scalarValue.startsWith("@") && event.getStartMark().getIndex() >= reader.getBufferIndex()) { + scalarValue = reader.readStringFromBuffer(event.getStartMark().getIndex(), event.getEndMark().getIndex() - 1); + } break; } BlockBuilder builder = blockStack.isEmpty() ? null : blockStack.peek(); diff --git a/rewrite-yaml/src/test/java/org/openrewrite/yaml/tree/MappingTest.java b/rewrite-yaml/src/test/java/org/openrewrite/yaml/tree/MappingTest.java index 972e3fd2a36..5252ce05d24 100644 --- a/rewrite-yaml/src/test/java/org/openrewrite/yaml/tree/MappingTest.java +++ b/rewrite-yaml/src/test/java/org/openrewrite/yaml/tree/MappingTest.java @@ -229,6 +229,20 @@ void suffixBeforeColon() { ); } + @Issue("https://github.com/openrewrite/rewrite/issues/3632") + @Test + void multilineScalar() { + rewriteRun( + yaml( + """ + data: &anc | + @this is a long string@ + bar: *anc + """ + ) + ); + } + @Test void literals() { rewriteRun(