Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.7.1 (Next)
============

* [#190](https://github.com/jenkinsci/ansicolor-plugin/pull/190): Don't leak formatting to metadata console lines - [@tszmytka](https://github.com/tszmytka).
* Your contribution here.

0.7.0 (05/23/2020)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public ConsoleAnnotator<Object> annotate(@Nonnull Object context, @Nonnull Marku
break;
case STOP:
return FACTORY.newInstance(context);
case IGNORE:
return this;
default:
if (colorMapName == null) {
colorMapName = defaultColorMapName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
* Action for issuing commands to ColorConsoleAnnotator
*/
public class ColorizedAction extends InvisibleAction {
private static final String TAG_PIPELINE_INTERNAL = "<span class=\"pipeline-new-node\"";
static final ColorizedAction CONTINUE = new ColorizedAction("", Command.CONTINUE);
static final ColorizedAction IGNORE = new ColorizedAction("", Command.IGNORE);

private final UUID id;

Expand All @@ -48,7 +50,8 @@ public class ColorizedAction extends InvisibleAction {
public enum Command {
START,
STOP,
CONTINUE
CONTINUE,
IGNORE
}

public ColorizedAction(String colorMapName, Command command) {
Expand Down Expand Up @@ -78,6 +81,6 @@ public static ColorizedAction parseAction(MarkupText text, Run<?, ?> run) {
final String id = line.substring(from, to);
return run.getActions(ColorizedAction.class).stream().filter(a -> id.equals(a.getId().toString())).findAny().orElse(CONTINUE);
}
return CONTINUE;
return line.contains(TAG_PIPELINE_INTERNAL) ? IGNORE : CONTINUE;
}
}
27 changes: 26 additions & 1 deletion src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testGetColorMapNameVga() {
public LoggerRule logging = new LoggerRule().record(ColorConsoleAnnotator.class, Level.FINER);

@Test
public void testPipelineStep() throws Exception {
public void testPipelineStep() {
story.addStep(new Statement() {

@Override
Expand Down Expand Up @@ -111,6 +111,31 @@ public void canRenderMultiplePipelineSteps() {
);
}

@Issue("JENKINS-61598")
@Test
public void willNotLeakFormattingToMetadataLines() {
final String script = "ansiColor('xterm') {\n" +
" echo '\033[33mYellow words, white background.'\n" +
" echo '\033[35mMagenta words, white background.'\n" +
"}";
String nl = System.lineSeparator();
assertOutputOnRunningPipeline(
Arrays.asList(
"<span style=\"color: #CDCD00;\">Yellow words, white background." + nl + "</span>",
"[Pipeline] echo",
"<span style=\"color: #CD00CD;\">Magenta words, white background." + nl + "</span>",
"[Pipeline] }"
),
Arrays.asList(
"\033[33mYellow words, white background.",
"<span style=\"color: #CDCD00;\">[Pipeline] echo",
"\033[35mMagenta words, white background.",
"<span style=\"color: #CD00CD;\">[Pipeline] }" + nl + "</span>"
),
script
);
}

private void assertOutputOnRunningPipeline(Collection<String> expectedOutput, Collection<String> notExpectedOutput, String pipelineScript) {
story.addStep(new Statement() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,18 @@ public void willReturnDefaultIfLogDoesntContainAnnotation() {
}

@Test
public void willReturnDefaultIfLogAnnotationPointsToNonexistingAction() {
public void willReturnDefaultIfLogAnnotationPointsToNonexistentAction() {
final MarkupText markupText = new MarkupText("Log line");
markupText.addMarkup(0, TAG_ACTION_BEGIN + "\"identifier_not_in_actions\"" + TAG_ACTION_END);
assertEquals(CONTINUE, ColorizedAction.parseAction(markupText, buildRun));
}

@Test
public void willReturnCommandIgnoreOnPipelineInternalLine() {
final MarkupText markupText = new MarkupText("Some internal line");
markupText.addMarkup(0, "<span class=\"pipeline-new-node\">");
System.out.println(markupText.toString(false));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging? Remove.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh the shame ;-)
Believe it or not I never do this.
Removed.

final ColorizedAction colorizedAction = ColorizedAction.parseAction(markupText, buildRun);
assertEquals(ColorizedAction.Command.IGNORE, colorizedAction.getCommand());
}
}