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

SassScriptLexer complaining about undefined index... #49

Open anandkkpr opened 12 years ago

anandkkpr commented 12 years ago

Hi! I'm not too sure where the problem is coming from but I'm getting a PHP Notice.

I've found a solution, essentially a check is needed to ensure that a usage of preg_match() actually returns matches. The new code simply has a condition that confirms the returned variable is an array and isn't empty.

As I said earlier, I'm really unsure about what might be causing the notice on my end and it's quite possible that it has something to do with the syntax in my SCSS file.

Error: Notice: Undefined offset: 1 in SassScriptLexer->lex() (line 76 of C:\wamp\www\presence\1530chestnut.com\sites\all\libraries\phpsass\script\SassScriptLexer.php).

// CODE FROM SCSS FILE
@mixin background-gradient($from, $to, $alpha: 1.0) {
  $rgbaTo:      rgba($to, $alpha);
  $rgbaFrom:    rgba($from, $alpha);
  $ieHexTo:     ie-hex-str($rgbaTo);
  $ieHexFrom:   ie-hex-str($rgbaFrom);

/* Old browsers */
  background: $from;
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
  background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3ZGI5ZTgiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
/* Chrome10+,Safari5.1+ */
  background: -webkit-linear-gradient(top, $rgbaFrom 0%, $rgbaTo 100%);
/* Chrome,Safari4+ */
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, $rgbaFrom), color-stop(100%, $rgbaTo));
/* FF3.6+ */
  background: -moz-linear-gradient(top, $rgbaFrom 0%, $rgbaTo 100%);
/* IE10+ */
  background: -ms-linear-gradient(top, $rgbaFrom 0%, $rgbaTo 100%);
/* Opera 11.10+ */
  background: -o-linear-gradient(top, $rgbaFrom 0%, $rgbaTo 100%);
/* W3C */
  background: linear-gradient(to bottom, $rgbaFrom 0%, $rgbaTo 100%);
/* IE lte 8 */
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = $ieHexFrom, endColorstr = $ieHexTo);
/* IE8 */
  ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = $ieHexFrom, endColorstr = $ieHexTo);
}
/*----------------------------------------------------------------------------------------
OLD CODE - @file SassScriptLexer.php
----------------------------------------------------------------------------------------*/
if (($match = $this->isWhitespace($string)) !== false) { // Line No. 67
  $tokens[] = null;
}
elseif (($match = SassScriptFunction::isa($string)) !== false) {
  preg_match(SassScriptFunction::MATCH_FUNC, $match, $matches);
  $args = array();
  foreach (SassScriptFunction::extractArgs($matches[SassScriptFunction::ARGS], false, $context) as $key => $expression) {
    $args[$key] = $this->parser->evaluate($expression, $context);
  }
  $tokens[] = new SassScriptFunction($matches[SassScriptFunction::NAME], $args);
}

Hope this helps!

anandkkpr commented 12 years ago

EDIT: Found that the background reset for IE9 that directly adds an svg image - the line that says "url(data:image/svg+xml..." - is what is causing the issue.

The fix I mentioned doesn't work, it breaks the statement. Am digging a bit more into it to see if I can offer any further input.

I'm removing my suggested code as it didn't work.

richthegeek commented 12 years ago

Try wrapping the URL in quotes, that should stop it being parsed as anything else.