Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-12782] Don't match word boundary if first or last
Browse files Browse the repository at this point in the history
character is not alpha numeric.
  • Loading branch information
uhafner committed Feb 20, 2012
1 parent 02d2b39 commit 0e484b0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .classpath
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="src" output="target/classes" path="target/generated-sources/localizer">
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/tasks/parser/Task.java
Expand Up @@ -67,5 +67,11 @@ public String getMatch() {
return getType() + ": " + getDetailMessage();
}
}

/** {@inheritDoc} */
@Override
public String toString() {
return super.toString() + getDetailMessage();
}
}

9 changes: 6 additions & 3 deletions src/main/java/hudson/plugins/tasks/parser/TaskScanner.java
Expand Up @@ -87,12 +87,15 @@ private Pattern compile(final String tagIdentifiers, final boolean ignoreCase) {
for (int i = 0; i < tags.length; i++) {
String tag = tags[i].trim();
if (StringUtils.isNotBlank(tag)) {
StringBuilder actual = new StringBuilder();
if (Character.isLetterOrDigit(tag.charAt(0))) {
regexps.add(WORD_BOUNDARY + tag + WORD_BOUNDARY);
actual.append(WORD_BOUNDARY);
}
else {
regexps.add(tag + WORD_BOUNDARY);
actual.append(tag);
if (Character.isLetterOrDigit(tag.charAt(tag.length() - 1))) {
actual.append(WORD_BOUNDARY);
}
regexps.add(actual.toString());
}
}
int flags;
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/hudson/plugins/tasks/parser/TaskScannerTest.java
Expand Up @@ -34,6 +34,21 @@ public class TaskScannerTest {
/** Error message. */
private static final String WRONG_NUMBER_OF_TASKS_ERROR = "Wrong number of tasks found.";

/**
* Parses a warning log with !!! and !!!! warnings.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-12782">Issue 12782</a>
*/
@Test
public void issue12782() throws IOException {
InputStream file = TaskScannerTest.class.getResourceAsStream("issue12782.txt");

Collection<Task> result = new TaskScanner("!!!!!", "!!!", "", false).scan(new InputStreamReader(file));
assertEquals(WRONG_NUMBER_OF_TASKS_ERROR, 3, result.size());
}

/**
* Checks whether we find tasks at word boundaries.
*
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/hudson/plugins/tasks/parser/issue12782.txt
@@ -0,0 +1,6 @@
This is a text

!!!: here we have a task with priority NORMAL

!!!!!: here another task with priority HIGH

0 comments on commit 0e484b0

Please sign in to comment.