Skip to content

Commit

Permalink
Fix JENKINS-38420
Browse files Browse the repository at this point in the history
Add optional whitespace before the end brace
  • Loading branch information
slide committed Sep 21, 2016
1 parent d87f1ea commit e9b416c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,5 @@ work
.classpath
.settings
.idea

.vscode/
5 changes: 5 additions & 0 deletions src/main/java/org/jenkinsci/plugins/tokenmacro/Parser.java
Expand Up @@ -97,10 +97,15 @@ Rule DelimitedToken() throws InterruptedException, MacroEvaluationException, IOE
Sequence(Identifier(), startToken()),
Optional(Expansion()),
Optional(Arguments()),
Optional(Spacing()),
'}',
processToken());
}

Rule WhiteSpace() {
return ZeroOrMore(AnyOf(" \t\f"));
}

Rule EscapedToken() {
return FirstOf(EscapedDelimitedToken(), EscapedNonDelimitedToken());
}
Expand Down
22 changes: 18 additions & 4 deletions src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java
@@ -1,10 +1,8 @@
package org.jenkinsci.plugins.tokenmacro;

import com.google.common.collect.ListMultimap;
import hudson.model.AbstractBuild;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.TaskListener;
import hudson.Launcher;
import hudson.model.*;
import hudson.util.StreamTaskListener;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -176,6 +174,22 @@ public void testException() throws Exception {
assertEquals("${TEST_NESTEDX,abc=\"def\",abc=\"ghi\",jkl=true}", TokenMacro.expand(b,listener,"${TEST_NESTEDX,abc=\"def\",abc=\"ghi\",jkl=true}",false,null));
}

@Test
@Issue("JENKINS-38420")
public void testJENKINS_38420() throws Exception {
FreeStyleProject project = j.createFreeStyleProject("foo");
project.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().println("<span class=\"timestamp\"><b>14:58:18</b> </span>version: 1.0.0-SNAPSHOT");
return true;
}
});
FreeStyleBuild b = project.scheduleBuild2(0).get();
final String result = TokenMacro.expand(b, listener, "${BUILD_LOG_REGEX, regex=\"^.*?version: (.*?)$\", substText=\"$1\", maxMatches=1, showTruncatedLines=false }", false, null);
assertEquals("1.0.0-SNAPSHOT\n", result);
}

@Test
public void testAutoComplete() throws Exception {
List<String> suggestions = TokenMacro.getAutoCompleteList("LKJLKJ");
Expand Down

0 comments on commit e9b416c

Please sign in to comment.