1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-05 02:39:47 +02:00

Don't run filename patterns through preg_quote twice

This would result in extra slashes, e.g.
    '/\/([0-9]+?)\s\\\-\s(.+?)\..+$/' instead of
    '/\/([0-9]+?)\s\-\s(.+?)\..+$/'

There are some unrelated cosmetic changes as well.
This commit is contained in:
Paul Arthur 2012-03-31 20:37:38 -04:00
parent 65ad781927
commit 425ecbbb3a
2 changed files with 22 additions and 13 deletions

View file

@ -4,6 +4,8 @@
--------------------------------------------------------------------------
v.3.6-Alpha2
- Fixed an issue with filename pattern matching when patterns contained
characters that are part of regex syntax (such as -)
- Fixed display of logic operator in rules (reported by Twister)
- Fixed newsearch issue preventing use of more than 9 rules
(reported by Twister)

View file

@ -941,26 +941,33 @@ class vainfo {
$slash_type = '\\';
}
// Combine the patterns
$pattern = preg_quote($this->_dir_pattern) . $slash_type . preg_quote($this->_file_pattern);
preg_match_all("/\%\w/",$pattern,$elements);
// Pull out the pattern codes into an array
preg_match_all('/\%\w/', $pattern, $elements);
$preg_pattern = preg_quote($pattern);
$preg_pattern = preg_replace("/\%[Ty]/","([0-9]+?)",$preg_pattern);
$preg_pattern = preg_replace("/\%\w/","(.+?)",$preg_pattern);
$preg_pattern = str_replace("/","\/",$preg_pattern);
$preg_pattern = str_replace(" ","\s",$preg_pattern);
$preg_pattern = "/" . $preg_pattern . "\..+$/";
preg_match($preg_pattern,$filename,$matches);
/* Cut out the Full line, we don't need that */
array_shift($matches);
// Mangle the pattern by turning the codes into regex captures
$pattern = preg_replace('/\%[Ty]/', '([0-9]+?)', $pattern);
$pattern = preg_replace('/\%\w/', '(.+?)', $pattern);
$pattern = str_replace('/', '\/', $pattern);
$pattern = str_replace(' ', '\s', $pattern);
$pattern = '/' . $pattern . '\..+$/';
/* Foreach through what we've found */
foreach ($matches as $key=>$value) {
// Pull out our actual matches
preg_match($pattern, $filename, $matches);
// The first element is the full match text
$matched = array_shift($matches);
debug_event('vainfo', $pattern . ' matched ' . $matched . ' on ' . $filename, 5);
// Iterate over what we found
foreach ($matches as $key => $value) {
$new_key = translate_pattern_code($elements['0'][$key]);
if ($new_key) {
$results[$new_key] = $value;
}
} // end foreach matches
}
$results['size'] = filesize($filename);