Skip to content

Commit 39fbb5f

Browse files
committed
Github: revise branch validation regex
The validation now follows the rules defined in git check-ref-format man page [1] Issue #193 [1] http://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
1 parent 30c99a5 commit 39fbb5f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

SourceGithub/SourceGithub.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,21 @@ public function update_repo( $p_repo ) {
211211
$f_hub_app_secret = gpc_get_string( 'hub_app_secret' );
212212
$f_master_branch = gpc_get_string( 'master_branch' );
213213

214-
if ( !preg_match( '/^(\*|[a-zA-Z0-9_\., -]*)$/', $f_master_branch ) ) {
214+
# Git branch name validation regex, based on rules defined in man page
215+
# http://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
216+
# @TODO this should probably be moved to Source so the logic can be reused in other git-based plugins
217+
static $s_valid_branch_regex = '%'
218+
# Must not start with '/'; cannot contain '/.', '//', '@{' or '\';
219+
# cannot be a single '@'.
220+
. '^(?!/|.*([/.]\.|//|@\{|\\)|@$)'
221+
# One or more chars, except the following: ASCII control, space,
222+
# tilde, caret, colon, question mark, asterisk, open bracket.
223+
. '[^\000-\037\177 ~^:?*[]+'
224+
# Must not end with '.lock', '/' or '.'
225+
. '(?<!\.lock|[/.])$'
226+
. '%';
227+
228+
if ( !preg_match( $s_valid_branch_regex, $f_master_branch ) ) {
215229
plugin_error( self::ERROR_INVALID_PRIMARY_BRANCH );
216230
}
217231

0 commit comments

Comments
 (0)