richthegeek / phpsass

A compiler for SASS/SCSS written in PHP, brought up to date (approx 3.2) from a fork of PHamlP: http://code.google.com/p/phamlp/
http://phpsass.com/
382 stars 83 forks source link

infinity loop in script/SassScriptLexer.php #179

Closed laruence closed 8 years ago

laruence commented 8 years ago

Hey:

I am Xinchen Hui, PHP7 core developer, I found an infinity loop in your repo while I was looking into a bug report relates to your repo: https://bugs.php.net/bug.php?id=71179

the problem is since PHP7, substr("", 0) will return "" instead of false, which is documented in http://php.net/manual/en/function.substr.php,

so your codes will result in infinity loop as you are trying to compare the result with false.

here is a quick fix:

diff --git a/script/SassScriptLexer.php b/script/SassScriptLexer.php
index 2ac33bb..c6b08a5 100755
--- a/script/SassScriptLexer.php
+++ b/script/SassScriptLexer.php
@@ -67,7 +67,7 @@ class SassScriptLexer
     }
    $tokens = array();
     // whilst the string is not empty, split it into it's tokens.
-    while ($string !== false) {
+    while (strlen($string)) {
       if (($match = $this->isWhitespace($string)) !== false) {
         $tokens[] = null;
       } elseif (($match = SassScriptFunction::isa($string)) !== false) {

please have a look... thanks

am05mhz commented 8 years ago

Hi Xinchen Hui, thanks for finding the bug in phpsass on php7.

i think this is the better approach to fix the bug by emulating the old behavior:

 // whilst the string is not empty, split it into it's tokens.
 while ($string !== false) {
    ...
    if ($string === '')
       $string = false;
 }
joejoseph00 commented 8 years ago

Thanks, this is fixed and passing in this pull request https://github.com/richthegeek/phpsass/pull/184

If you want, clone my repo https://github.com/joejoseph00/phpsass until this is merged.