diff --git a/src/main/java/org/jenkinsci/plugins/tokenmacro/Parser.java b/src/main/java/org/jenkinsci/plugins/tokenmacro/Parser.java index 4902deb..415d52a 100644 --- a/src/main/java/org/jenkinsci/plugins/tokenmacro/Parser.java +++ b/src/main/java/org/jenkinsci/plugins/tokenmacro/Parser.java @@ -103,13 +103,20 @@ private void parseToken(CharacterIterator c) throws MacroEvaluationException, IO throw new MacroEvaluationException("Missing $ in macro usage"); } + char last = c.current(); c.next(); if(c.current() == '$') { parseEscapedToken(c); } else if(c.current() == '{') { parseDelimitedToken(c); - } else { + } else if(Character.isLetter(c.current())) { parseNonDelimitedToken(c); + } else { + output.append(last); + if(c.current() != CharacterIterator.DONE) { + output.append(c.current()); + } + c.next(); } } diff --git a/src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java b/src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java index f874cfc..7f34ad4 100644 --- a/src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java +++ b/src/test/java/org/jenkinsci/plugins/tokenmacro/TokenMacroTest.java @@ -223,6 +223,18 @@ public void testThatATokenMacroListWithANullEntryDoesNotExplode() throws Excepti TokenMacro.expand(b, listener, "${TEST_PRIVATE}${BUILD_URL}${TEST2_PRIVATE}", true, badList)); } + @Test + @Issue("JENKINS-67862") + public void testNoToken() throws Exception { + FreeStyleProject p = j.createFreeStyleProject("foo"); + FreeStyleBuild b = p.scheduleBuild2(0).get(); + assertEquals("^(?:.*/)?master$|^(?:.*/)?(feature|release)/.* ",TokenMacro.expandAll(b, TaskListener.NULL, "^(?:.*/)?master$|^(?:.*/)?(feature|release)/.* ")); + + p = j.createFreeStyleProject("foo2"); + b = p.scheduleBuild2(0).get(); + assertEquals("^false$",TokenMacro.expandAll(b, TaskListener.NULL, "^false$")); + } + public class PrivateTestMacro extends TokenMacro { private static final String MACRO_NAME = "TEST_PRIVATE";