Browse Source

Escape special chars in URL rules.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
e56d60ad49
  1. 12
      framework/yii/web/UrlRule.php

12
framework/yii/web/UrlRule.php

@ -143,7 +143,16 @@ class UrlRule extends Object
} }
} }
$tr = $tr2 = []; $tr = [
'.' => '\\.',
'*' => '\\*',
'$' => '\\$',
'[' => '\\[',
']' => '\\]',
'(' => '\\(',
')' => '\\)',
];
$tr2 = [];
if (preg_match_all('/<(\w+):?([^>]+)?>/', $this->pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { if (preg_match_all('/<(\w+):?([^>]+)?>/', $this->pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$name = $match[1][0]; $name = $match[1][0];
@ -166,7 +175,6 @@ class UrlRule extends Object
} }
} }
} }
$tr['.'] = '\\.';
$this->_template = preg_replace('/<(\w+):?([^>]+)?>/', '<$1>', $this->pattern); $this->_template = preg_replace('/<(\w+):?([^>]+)?>/', '<$1>', $this->pattern);
$this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u'; $this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u';

Loading…
Cancel
Save