You are here

public function CSSCompression_Cleanup::removeInjections in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg_css_compress/css-compressor-3.x/src/lib/Cleanup.inc \CSSCompression_Cleanup::removeInjections()

Removes '\' from possible splitter characters in URLs

Parameters

(string) css: Full css sheet:

File

advagg_css_compress/css-compressor-3.x/src/lib/Cleanup.inc, line 128

Class

CSSCompression_Cleanup
CSS Compressor [VERSION] [DATE] Corey Hart @ http://www.codenothing.com

Code

public function removeInjections($css) {

  // Remove escaped characters
  foreach ($this->rescape as $regex) {
    $pos = 0;
    while (preg_match($regex, $css, $match, PREG_OFFSET_CAPTURE, $pos)) {
      $value = $match[1][0] . str_replace($this->escaped['search'], $this->escaped['replace'], $match[2][0]) . $match[3][0];
      $css = substr_replace($css, $value, $match[0][1], strlen($match[0][0]));
      $pos = $match[0][1] + strlen($value) + 1;
    }
  }

  // Remove token injections
  $pos = 0;
  while (preg_match($this->rtoken, $css, $match, PREG_OFFSET_CAPTURE, $pos)) {
    $value = $match[2][0];
    $id = substr($css, $match[0][1] - 4, 4) == '[id=' ? true : false;
    $class = substr($css, $match[0][1] - 7, 7) == '[class=' ? true : false;
    if (preg_match($this->rspace, $value) || !$id && !$class) {
      $quote = preg_match($this->rquote, $value) ? "\"" : "'";
      $value = "{$quote}{$value}{$quote}";
      $css = substr_replace($css, $value, $match[0][1], strlen($match[0][0]));
      $pos = $match[0][1] + strlen($value) + 1;
    }
    else {
      $css = substr_replace($css, $value, $match[0][1], strlen($match[0][0]));
      $pos = $match[0][1] + strlen($value) + 1;
    }
  }
  return $css;
}