nemccarthy / stash-pullrequest-builder-plugin

A Jenkins plugin for Building Stash Pull Requests
https://wiki.jenkins-ci.org/display/JENKINS/Stash+pullrequest+builder+plugin
Other
64 stars 130 forks source link

Comment log checker does not handle build names with regex characters #27

Closed dalewking closed 8 years ago

dalewking commented 9 years ago

The regular expressions created for looking for build started and build finished message in the comments is inserting the build job name directly as part of the regular expression. That works if the build job name is a simple name, but in our case we had some text in parentheses in the name of the build job. The regex parser took that as a capture group so the match failed because it would not match the parentheses in the name.

You should use a capture group for the job name and then compare the captured text to the build job name or else use java.util.regex.Pattern.quote to add any necessary escape characters. Here is a patch that fixes it:

diff --git a/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java b/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
index 2d9bf76..efca26d 100644
--- a/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
+++ b/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
@@ -157,8 +157,9 @@ public class StashRepository {
                     }

                     //These will match any start or finish message -- need to check commits
-                    String project_build_start = String.format(BUILD_START_REGEX, builder.getProject().getDisplayName());
-                    String project_build_finished = String.format(BUILD_FINISH_REGEX, builder.getProject().getDisplayName());
+                    String escapedBuildName = Pattern.quote(builder.getProject().getDisplayName());
+                    String project_build_start = String.format(BUILD_START_REGEX, escapedBuildName);
+                    String project_build_finished = String.format(BUILD_FINISH_REGEX, escapedBuildName);
                     Matcher startMatcher = Pattern.compile(project_build_start, Pattern.CASE_INSENSITIVE).matcher(content);
                     Matcher finishMatcher = Pattern.compile(project_build_finished, Pattern.CASE_INSENSITIVE).matcher(content);
dalewking commented 9 years ago

Moved the issue to the Jenkins Jira: https://issues.jenkins-ci.org/browse/JENKINS-29274?filter=-2

dalewking commented 9 years ago

Reopened as requested on Jenkins Jira

nemccarthy commented 8 years ago

Please open a PR

nemccarthy commented 8 years ago

This has been fixed