Permalink
Browse files

Made hyphen escaping clearer in FileNameFilter and URLSegmentFilter

Does not actually change behaviour, but ensures that the hyphen
is not interpreted as a range identifier should it be placed
between two characters which PCRE regards as "rangeable".
  • Loading branch information...
1 parent 561e629 commit 86940aa6849003ebef3154b372a0a9d631061621 @chillu chillu committed Dec 19, 2012
Showing with 4 additions and 4 deletions.
  1. +1 −1 filesystem/FileNameFilter.php
  2. +3 −3 model/URLSegmentFilter.php
View
2 filesystem/FileNameFilter.php
@@ -39,7 +39,7 @@ class FileNameFilter extends Object {
static $default_replacements = array(
'/\s/' => '-', // remove whitespace
'/_/' => '-', // underscores to dashes
- '/[^A-Za-z0-9+.-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
+ '/[^A-Za-z0-9+.\-]+/' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
'/[\-]{2,}/' => '-', // remove duplicate dashes
'/^[\.\-_]+/' => '', // Remove all leading dots, dashes or underscores
);
View
6 model/URLSegmentFilter.php
@@ -29,7 +29,7 @@ class URLSegmentFilter extends Object {
'/&/u' => '-and-',
'/\s/u' => '-', // remove whitespace
'/_/u' => '-', // underscores to dashes
- '/[^A-Za-z0-9+.-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
+ '/[^A-Za-z0-9+.\-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
'/[\-]{2,}/u' => '-', // remove duplicate dashes
'/^[\.\-_]/u' => '', // Remove all leading dots, dashes or underscores
);
@@ -66,8 +66,8 @@ public function filter($name) {
$replacements = $this->getReplacements();
// Unset automated removal of non-ASCII characters, and don't try to transliterate
- if($this->getAllowMultibyte() && isset($replacements['/[^A-Za-z0-9+.-]+/u'])) {
- unset($replacements['/[^A-Za-z0-9+.-]+/u']);
+ if($this->getAllowMultibyte() && isset($replacements['/[^A-Za-z0-9+.\-]+/u'])) {
+ unset($replacements['/[^A-Za-z0-9+.\-]+/u']);
}
foreach($replacements as $regex => $replace) {

0 comments on commit 86940aa

Please sign in to comment.