Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
! Don't bother with backslashes inside comments, PHP ignores them any…
…way. (Subs-CachePHP.php)

! PHP single-line comments can be 'stopped' by a ?> sign, this should fix it. However I haven't seen multi-line comments behave the same, so I'm leaving those aside for now. Would appreciate some feedback, but it's no big deal since ?> is barely used in Wedge. (Subs-CachePHP.php)

@ This actually fixes a bug (and only one) in Wedge-- that occurred when sending non-HTML posts in French. It was broken for the last 3 years, and I never understood why. Now I know. Someone at SMF used a backslash at the end of a comment. The fools.
  • Loading branch information
Nao committed Apr 18, 2017
1 parent e80acb5 commit 5973dac
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions core/app/Subs-CachePHP.php
Expand Up @@ -72,11 +72,11 @@ function minify_php($file, $remove_whitespace = false)
}

if ($php[$pos + 1] === '/') // Remove //
$look_for = array("\r", "\n", "\r\n");
$look_for = ["\r", "\n", "\r\n", '?' . '>'];
else // Remove /* ... */
$look_for = '*/';

$end = find_next($php, $pos + 1, $look_for);
$end = find_next($php, $pos + 1, $look_for, true);
if ($end === false)
break;
if (!is_array($look_for))
Expand Down Expand Up @@ -109,7 +109,7 @@ function minify_php($file, $remove_whitespace = false)
@unlink($file);
}

function find_next(&$php, $pos, $search_for)
function find_next(&$php, $pos, $search_for, $in_comment = false)
{
if (is_array($search_for))
{
Expand All @@ -131,12 +131,15 @@ function find_next(&$php, $pos, $search_for)
return false;
}

$check_before = $next;
$escaped = false;
while (--$check_before >= 0 && $php[$check_before] == '\\')
$escaped = !$escaped;
if ($escaped)
return find_next($php, ++$next, $search_for);
if (!$in_comment)
{
$check_before = $next;
$escaped = false;
while (--$check_before >= 0 && $php[$check_before] == '\\')
$escaped = !$escaped;
if ($escaped)
return find_next($php, ++$next, $search_for);
}
return $next;
}

Expand Down

0 comments on commit 5973dac

Please sign in to comment.