Skip to content

Commit 920fc05

Browse files
committed
[*] some preg_match
some preg_match
1 parent ff1bca8 commit 920fc05

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

src/SvnAdmin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ public function create($path, array $options = null)
2020
throw new SvnException('Empty path parameter for "svnadmin create" command.');
2121
}
2222

23-
$pattern = '/^([a-z0-9\_\-.]+)$/i';
23+
// 目录名过滤特殊字符
24+
$un_pattern = '/[\'\"\?\*\|\/\\\\<>: ]+/'; // (\\\\) means (\)
2425
$repo_name = basename($path);
25-
26-
if (!preg_match($pattern, $repo_name)) {
26+
// 不影响中文目录
27+
if (preg_match($un_pattern, $repo_name)) {
2728
throw new SvnException('Invalid repository name: ' . $repo_name . '');
2829
}
2930

src/SvnConfAuthz.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ public function addRepositoryPath($repopath)
382382
}
383383

384384
// Validate the $repopath string.
385+
// 不影响中文目录
385386
$pattern = '/^[A-Za-z0-9\_\-.]+:\/.*$/i';
386387
if ($repopath != "/" && !preg_match($pattern, $repopath)) {
387388
throw new SvnException('Invalid repository name. (Pattern: ' . $pattern . ')');
@@ -432,6 +433,7 @@ public function groupExists($groupname)
432433
public function createGroup($groupname)
433434
{
434435
// Validate the groupname.
436+
// 组名正则
435437
$pattern = '/^[A-Za-z0-9\-\_]+$/i';
436438
if (!preg_match($pattern, $groupname)) {
437439
throw new SvnException('Invalid group name "' . $groupname .

src/traits/SvnEncode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public function encodeUrlPath($uri, $escape = true)
4040
}
4141

4242
// Automatic prepend the 'file://' prefix (if nothing else is given).
43-
if (preg_match('/^[a-z0-9+]+:\/\//i', $uri) == 0) {
43+
// 不影响中文目录
44+
$pattern = '/^[a-z0-9+]+:\/\//i';
45+
if (preg_match($pattern, $uri) == 0) {
4446
if (strpos($uri, '/') === 0) {
4547
$uri = 'file://' . $uri;
4648
} else {

tests/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
'PARENT' => '/home/breeze/http/svn/repos',
66
'TYPE' => array('COMPANY' => 'company', 'PERSON' => 'person'),
77
'SVNADMIN' => '/usr/bin/svnadmin',
8-
'SVNCONF' => '/conf',
98
'SVNCLIENT' => '/usr/bin/svn',
9+
'SVNCONF' => '/conf',
1010
'SVNCONF_AUTHZ' => '/conf/authz',
1111
),
1212
);

tests/test.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@
44
use BL\LibSvn\SvnClient as Svn;
55
use BL\LibSvn\SvnConfAuthz as SvnAuthz;
66

7-
require '../vendor/autoload.php';
7+
require __DIR__ . '/../vendor/autoload.php';
88

99
$config = require __DIR__ . '/config.php';
1010

1111
var_dump(__DIR__);
12+
$parent_dir = $config['SVN']['PARENT'];
1213
$svnclient_bin = $config['SVN']['SVNCLIENT'];
13-
$svn = new Svn($svnclient_bin);
14+
$svnadmin_bin = $config['SVN']['SVNADMIN'];
15+
16+
$svn = $svnclient = new Svn($svnclient_bin);
17+
$svnadmin = new SvnAdmin($svnadmin_bin);
18+
19+
$name = 'test123';
20+
$parent_dir = __DIR__;
21+
$repo = $parent_dir . '/' . $name;
22+
$result = $svnadmin->create($repo);

0 commit comments

Comments
 (0)