mirror of
https://github.com/matthiasmullie/minify.git
synced 2025-02-25 05:02:32 +01:00
Automatically make registered patterns match from string start
This commit is contained in:
parent
f1b565bc99
commit
eb60ec7964
10
src/JS.php
10
src/JS.php
@ -183,7 +183,7 @@ class JS extends Minify
|
||||
return $placeholder;
|
||||
};
|
||||
|
||||
$this->registerPattern('/^([\'"])(.*?)(?<!\\\\)\\1/s', $callback);
|
||||
$this->registerPattern('/([\'"])(.*?)(?<!\\\\)\\1/s', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,10 +192,10 @@ class JS extends Minify
|
||||
protected function stripComments()
|
||||
{
|
||||
// single-line comments
|
||||
$this->registerPattern('/^\/\/.*$[\r\n]*/m', '');
|
||||
$this->registerPattern('/\/\/.*$[\r\n]*/m', '');
|
||||
|
||||
// multi-line comments
|
||||
$this->registerPattern('/^\/\*.*?\*\//s', '');
|
||||
$this->registerPattern('/\/\*.*?\*\//s', '');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,10 +233,10 @@ class JS extends Minify
|
||||
// a = b / c; d = e / f
|
||||
preg_match_all('/\[(.*?)\]/', $this->variable, $parts);
|
||||
$last = $parts[1][1];
|
||||
$this->registerPattern('/^[' . $last . '\}\]\)]\s*\/(?![\/\*])/u', '\\0');
|
||||
$this->registerPattern('/[' . $last . '\}\]\)]\s*\/(?![\/\*])/u', '\\0');
|
||||
|
||||
// it's a regex if we can find an opening & (non-escaped) closing /
|
||||
$this->registerPattern('/^\/(.*?(?<!\\\\)(\\\\\\\\)*)\//', $callback);
|
||||
$this->registerPattern('/\/(.*?(?<!\\\\)(\\\\\\\\)*)\//', $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,10 +125,10 @@ abstract class Minify
|
||||
*/
|
||||
protected function registerPattern($pattern, $replacement = '')
|
||||
{
|
||||
// doublecheck if pattern actually starts at beginning of content
|
||||
if (substr($pattern, 1, 1) !== '^') {
|
||||
throw new Exception('Pattern "' . $pattern . '" should start processing at the beginning of the string.');
|
||||
}
|
||||
// make sure pattern actually starts at beginning of content - we'll be
|
||||
// looping the content character by character, executing patterns
|
||||
// starting on exactly that character.
|
||||
if ($pattern[0] !== '^') $pattern = $pattern[0] . '^' . substr($pattern, 1);
|
||||
|
||||
$this->patterns[] = array($pattern, $replacement);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user