From 412c73c5092b1938bbed4b4fc7c5fd7b5dd28554 Mon Sep 17 00:00:00 2001 From: Vitaliy Ognev Date: Sun, 23 Dec 2012 14:01:26 +0200 Subject: [PATCH 1/3] fix situation when valid ref is a part of path --- src/GitList/Util/Repository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index 80d783d..16c1b33 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -199,7 +199,7 @@ class Repository // Otherwise, attempt to detect the ref using a list of the project's branches and tags $valid_refs = array_merge((array) $repository->getBranches(), (array) $repository->getTags()); foreach ($valid_refs as $k => $v) { - if (!preg_match("#{$v}/#", $input)) { + if (!preg_match("#^{$v}/#", $input)) { unset($valid_refs[$k]); } } From 06f65ca8e2694a5ff832e77dc80b22d5249dd8fc Mon Sep 17 00:00:00 2001 From: Vitaliy Ognev Date: Sun, 23 Dec 2012 14:32:32 +0200 Subject: [PATCH 2/3] should take 1st match --- src/GitList/Util/Repository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index 16c1b33..0236d14 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -207,7 +207,7 @@ class Repository // No exact ref match, so just try our best if (count($valid_refs) > 1) { preg_match('/([^\/]+)(.*)/', $input, $matches); - $branch = preg_replace('/^\/|\/$/', '', $matches[0]); + $branch = preg_replace('/^\/|\/$/', '', $matches[1]); } else { // Extract branch name $branch = array_shift($valid_refs); From 652af777aa03f1045b7170bfe1183e606f4ab072 Mon Sep 17 00:00:00 2001 From: Vitaliy Ognev Date: Sun, 23 Dec 2012 15:34:17 +0200 Subject: [PATCH 3/3] ensure ref name is encoded --- src/GitList/Util/Repository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index 0236d14..5659125 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -199,7 +199,7 @@ class Repository // Otherwise, attempt to detect the ref using a list of the project's branches and tags $valid_refs = array_merge((array) $repository->getBranches(), (array) $repository->getTags()); foreach ($valid_refs as $k => $v) { - if (!preg_match("#^{$v}/#", $input)) { + if (!preg_match(sprintf("#^%s/#", preg_quote($v, '#')), $input)) { unset($valid_refs[$k]); } }