Skip to content

Commit 439459e

Browse files
authored
Merge pull request #125 from tedious/keyword_detection_bug
Fix bug in keyword detections
2 parents 0393388 + d9c2bfa commit 439459e

7 files changed

+26
-3
lines changed

src/JShrink/Minifier.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,14 @@ protected function loop()
285285

286286
if ($this->b == '/') {
287287
$valid_tokens = "(,=:[!&|?\n";
288-
if (strpos($valid_tokens, $this->last_char) !== false || strpos($valid_tokens, $this->a) !== false) {
288+
289+
# Find last "real" token, excluding spaces.
290+
$last_token = $this->a;
291+
if ($last_token == " ") {
292+
$last_token = $this->last_char;
293+
}
294+
295+
if (strpos($valid_tokens, $last_token) !== false) {
289296
// Regex can appear unquoted after these symbols
290297
$this->saveRegex();
291298
} else if ($this->endsInKeyword()) {
@@ -644,11 +651,15 @@ protected static function isAlphaNumeric($char)
644651
}
645652

646653
protected function endsInKeyword() {
654+
655+
# When this function is called A is not yet assigned to output.
656+
$testOutput = $this->output . $this->a;
657+
647658
foreach(static::$keywords as $keyword) {
648-
if (str_ends_with($this->output, $keyword)) {
659+
if (str_ends_with($testOutput, $keyword)) {
649660
return true;
650661
}
651-
if (str_ends_with($this->output, $keyword . " ")) {
662+
if (str_ends_with($testOutput, $keyword . " ")) {
652663
return true;
653664
}
654665
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function test () {
2+
return this.indeterminate
3+
? 100
4+
: (100 * (this.options.value - this.min)) / (this.options.max - this.min)
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (D > (F/2)) {
2+
console.log('a')
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var value = currentRating/other
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function test(){return this.indeterminate?100:(100*(this.options.value-this.min))/(this.options.max-this.min)}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
if(D>(F/2)){console.log('a')}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var value=currentRating/other

0 commit comments

Comments
 (0)