Skip to content

Commit b9a80a5

Browse files
authored
fix: clear line continuation handling after a multiline instruction (#5)
* Clear continuation after multiline instruction
1 parent 526157a commit b9a80a5

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/main/java/com/github/jimschubert/rewrite/docker/internal/ParserState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void reset() {
3232
prefix = Space.EMPTY;
3333
rightPadding = Space.EMPTY;
3434
escapeChar = '\\';
35+
isContinuation = false;
3536
}
3637

3738
String getEscapeString() {

src/test/java/com/github/jimschubert/rewrite/docker/internal/DockerfileParserTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,35 @@ void testRunMultiline() {
845845
assertLiteral(args.get(7), Quoting.UNQUOTED, " ", "gcc", "");
846846
}
847847

848+
@Test
849+
void testRunMultilineClearsContinuation() {
850+
DockerfileParser parser = new DockerfileParser();
851+
Docker.Document doc = parser.parse(new ByteArrayInputStream(
852+
"""
853+
RUN echo Hello \\
854+
World
855+
# This is a comment
856+
# This is another comment
857+
""".getBytes(StandardCharsets.UTF_8)));
858+
859+
Docker.Stage stage = assertSingleStageWithChildCount(doc, 3);
860+
861+
Docker.Run cmd = (Docker.Run) stage.getChildren().get(0);
862+
assertEquals(Space.EMPTY, cmd.getPrefix());
863+
864+
List<Docker.Literal> args = cmd.getCommands();
865+
assertEquals(3, args.size());
866+
867+
assertLiteral(args.get(0), Quoting.UNQUOTED, " ", "echo", "");
868+
assertLiteral(args.get(1), Quoting.UNQUOTED, " ", "Hello", " \\\n");
869+
assertLiteral(args.get(2), Quoting.UNQUOTED, " ", "World", "");
870+
871+
Docker.Comment comment1 = (Docker.Comment) stage.getChildren().get(1);
872+
assertLiteral(comment1.getText(), Quoting.UNQUOTED, " ", "This is a comment", "");
873+
Docker.Comment comment2 = (Docker.Comment) stage.getChildren().get(2);
874+
assertLiteral(comment2.getText(), Quoting.UNQUOTED, " ", "This is another comment", "");
875+
}
876+
848877
/**
849878
* Test this example heredoc from the Dockerfile reference:
850879
* RUN <<EOF

0 commit comments

Comments
 (0)