diff options
author | Paul Arthur <paul.arthur@flowerysong.com> | 2012-03-31 20:37:38 -0400 |
---|---|---|
committer | Paul Arthur <paul.arthur@flowerysong.com> | 2012-03-31 20:44:41 -0400 |
commit | 425ecbbb3a6bf2142de5d3f81cb3add270f12b51 (patch) | |
tree | 4d512b50a10ddf67407ecc0ff4dabe0f3f52cf0f /lib/class/vainfo.class.php | |
parent | 65ad781927b3fa8a0ee6931900db8ee352698706 (diff) | |
download | ampache-425ecbbb3a6bf2142de5d3f81cb3add270f12b51.tar.gz ampache-425ecbbb3a6bf2142de5d3f81cb3add270f12b51.tar.bz2 ampache-425ecbbb3a6bf2142de5d3f81cb3add270f12b51.zip |
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.
Diffstat (limited to 'lib/class/vainfo.class.php')
-rw-r--r-- | lib/class/vainfo.class.php | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/class/vainfo.class.php b/lib/class/vainfo.class.php index 26da7bd8..298da73f 100644 --- a/lib/class/vainfo.class.php +++ b/lib/class/vainfo.class.php @@ -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); - - $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); - - /* Foreach through what we've found */ - foreach ($matches as $key=>$value) { + + // Pull out the pattern codes into an array + preg_match_all('/\%\w/', $pattern, $elements); + + // 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 . '\..+$/'; + + // 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); |