diff --git a/.gitignore b/.gitignore index 8467073..e8f2d67 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ # / /test /docs +.idea/ \ No newline at end of file diff --git a/min/builder/bm2.js b/min/builder/bm2.js index db92172..6b558ce 100644 --- a/min/builder/bm2.js +++ b/min/builder/bm2.js @@ -1,15 +1,15 @@ javascript:(function(){ var d = document ,c = d.cookie - ,m = c.match(/\bminDebug=([^; ]+)/) + ,m = c.match(/\bminifyDebug=([^; ]+)/) ,v = m ? decodeURIComponent(m[1]) : '' ,p = prompt('Debug Minify URIs on ' + location.hostname + ' which contain:' - + '\n(empty for none, space = OR)', v) + + '\n(empty for none, space = OR, * = any string, ? = any char)', v) ; if (p === null) return; p = p.replace(/^\s+|\s+$/, ''); v = (p === '') - ? 'minDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/' - : 'minDebug=' + encodeURIComponent(p) + '; path=/'; + ? 'minifyDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/' + : 'minifyDebug=' + encodeURIComponent(p) + '; path=/'; d.cookie = v; })(); \ No newline at end of file diff --git a/min/index.php b/min/index.php index 165c8d5..e36dfd5 100644 --- a/min/index.php +++ b/min/index.php @@ -36,18 +36,8 @@ foreach ($min_symlinks as $uri => $target) { } if ($min_allowDebugFlag) { - if (! empty($_COOKIE['minDebug'])) { - foreach (preg_split('/\\s+/', $_COOKIE['minDebug']) as $debugUri) { - if (false !== strpos($_SERVER['REQUEST_URI'], $debugUri)) { - $min_serveOptions['debug'] = true; - break; - } - } - } - // allow GET to override - if (isset($_GET['debug'])) { - $min_serveOptions['debug'] = true; - } + require_once 'Minify/DebugDetector.php'; + $min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($_COOKIE, $_GET, $_SERVER['REQUEST_URI']); } if ($min_errorLogger) { diff --git a/min/lib/Minify/DebugDetector.php b/min/lib/Minify/DebugDetector.php new file mode 100644 index 0000000..1def974 --- /dev/null +++ b/min/lib/Minify/DebugDetector.php @@ -0,0 +1,26 @@ + + */ +class Minify_DebugDetector { + public static function shouldDebugRequest($cookie, $get, $requestUri) + { + if (isset($get['debug'])) { + return true; + } + if (! empty($cookie['minifyDebug'])) { + foreach (preg_split('/\\s+/', $cookie['minifyDebug']) as $debugUri) { + $pattern = '@' . preg_quote($debugUri, '@') . '@i'; + $pattern = str_replace(array('\\*', '\\?'), array('.*', '.'), $pattern); + if (preg_match($pattern, $requestUri)) { + return true; + } + } + } + return false; + } +}