Commit 8d6a0458 authored by Robert Lyon's avatar Robert Lyon

Bug 1536895: Upgrade CSSTidy to 1.5.5

behatnotneeded

Change-Id: Iedc0bec19d31501104b9b63adf786147cf1c6321
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 2d664888
...@@ -2,7 +2,7 @@ CSSTidy in Mahara ...@@ -2,7 +2,7 @@ CSSTidy in Mahara
================= =================
Website: https://github.com/Cerdic/CSSTidy Website: https://github.com/Cerdic/CSSTidy
Version: 1.5.2 Version: 1.5.5
This library is used by clean_css, to strip out malicious CSS This library is used by clean_css, to strip out malicious CSS
......
...@@ -33,23 +33,28 @@ ...@@ -33,23 +33,28 @@
*/ */
/** /**
* Defines ctype functions if required * Defines ctype functions if required.
* @todo make them methods of csstidy class *
* @version 1.0 * @TODO: Make these methods of CSSTidy.
* @since 1.0.0
*/ */
if (!function_exists('ctype_space')) { if (!function_exists('ctype_space')){
/* ctype_space Check for whitespace character(s) */ /* ctype_space Check for whitespace character(s) */
function ctype_space($text) { function ctype_space($text){
return!preg_match("/[^\s\r\n\t\f]/", $text); return (1===preg_match("/^[ \r\n\t\f]+$/", $text));
} }
} }
if (!function_exists('ctype_alpha')) { if (!function_exists('ctype_alpha')){
/* ctype_alpha Check for alphabetic character(s) */ /* ctype_alpha Check for alphabetic character(s) */
function ctype_alpha($text) { function ctype_alpha($text){
return preg_match("/[a-zA-Z]/", $text); return (1===preg_match('/^[a-zA-Z]+$/', $text));
}
}
if (!function_exists('ctype_xdigit')){
/* ctype_xdigit Check for HEX character(s) */
function ctype_xdigit($text){
return (1===preg_match('/^[a-fA-F0-9]+$/', $text));
} }
} }
/** /**
...@@ -89,7 +94,7 @@ require('class.csstidy_optimise.php'); ...@@ -89,7 +94,7 @@ require('class.csstidy_optimise.php');
* An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php * An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php
* @package csstidy * @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2006 * @author Florian Schmitz (floele at gmail dot com) 2005-2006
* @version 1.5.2 * @version 1.5.5
*/ */
class csstidy { class csstidy {
...@@ -111,11 +116,11 @@ class csstidy { ...@@ -111,11 +116,11 @@ class csstidy {
* @access public * @access public
*/ */
public $cur_comments = array(); public $cur_comments = array();
/** /**
* Saves the parsed CSS (raw) * Saves the parsed CSS (raw)
* @var array * @var array
* @access public * @access private
*/ */
public $tokens = array(); public $tokens = array();
/** /**
* Printer class * Printer class
...@@ -154,7 +159,7 @@ class csstidy { ...@@ -154,7 +159,7 @@ class csstidy {
* @var string * @var string
* @access private * @access private
*/ */
public $version = '1.5.2'; public $version = '1.5.5';
/** /**
* Stores the settings * Stores the settings
* @var array * @var array
...@@ -309,6 +314,7 @@ class csstidy { ...@@ -309,6 +314,7 @@ class csstidy {
*/ */
$this->settings['optimise_shorthands'] = 1; $this->settings['optimise_shorthands'] = 1;
$this->settings['remove_last_;'] = true; $this->settings['remove_last_;'] = true;
$this->settings['space_before_important'] = false;
/* rewrite all properties with low case, better for later gzip OK, safe*/ /* rewrite all properties with low case, better for later gzip OK, safe*/
$this->settings['case_properties'] = 1; $this->settings['case_properties'] = 1;
/* sort properties in alpabetic order, better for later gzip /* sort properties in alpabetic order, better for later gzip
...@@ -328,7 +334,7 @@ class csstidy { ...@@ -328,7 +334,7 @@ class csstidy {
$this->settings['discard_invalid_properties'] = false; $this->settings['discard_invalid_properties'] = false;
$this->settings['css_level'] = 'CSS3.0'; $this->settings['css_level'] = 'CSS3.0';
$this->settings['preserve_css'] = false; $this->settings['preserve_css'] = false;
$this->settings['preserve_css_comment'] = false; $this->settings['preserve_css_comment'] = false;
$this->settings['timestamp'] = false; $this->settings['timestamp'] = false;
$this->settings['template'] = ''; // say that propertie exist $this->settings['template'] = ''; // say that propertie exist
$this->set_cfg('template','default'); // call load_template $this->set_cfg('template','default'); // call load_template
...@@ -629,7 +635,7 @@ class csstidy { ...@@ -629,7 +635,7 @@ class csstidy {
$this->at .= $this->_unicode($string, $i); $this->at .= $this->_unicode($string, $i);
} }
// fix for complicated media, i.e @media screen and (-webkit-min-device-pixel-ratio:1.5) // fix for complicated media, i.e @media screen and (-webkit-min-device-pixel-ratio:1.5)
elseif (in_array($string{$i}, array('(', ')', ':', '.'))) { elseif (in_array($string{$i}, array('(', ')', ':', '.', '/'))) {
$this->at .= $string{$i}; $this->at .= $string{$i};
} }
} else { } else {
...@@ -707,8 +713,8 @@ class csstidy { ...@@ -707,8 +713,8 @@ class csstidy {
$this->sel_separate[] = strlen($this->selector); $this->sel_separate[] = strlen($this->selector);
} elseif ($string{$i} === '\\') { } elseif ($string{$i} === '\\') {
$this->selector .= $this->_unicode($string, $i); $this->selector .= $this->_unicode($string, $i);
} elseif ($string{$i} === '*' && @in_array($string{$i + 1}, array('.', '#', '[', ':'))) { } elseif ($string{$i} === '*' && @in_array($string{$i + 1}, array('.', '#', '[', ':')) && ($i==0 OR $string{$i - 1}!=='/')) {
// remove unnecessary universal selector, FS#147 // remove unnecessary universal selector, FS#147, but not comment in selector
} else { } else {
$this->selector .= $string{$i}; $this->selector .= $string{$i};
} }
...@@ -848,7 +854,7 @@ class csstidy { ...@@ -848,7 +854,7 @@ class csstidy {
} }
} }
$previous_property = $this->property; $previous_property = $this->property;
$this->property = ''; $this->property = '';
$this->sub_value_arr = array(); $this->sub_value_arr = array();
$this->value = ''; $this->value = '';
......
...@@ -269,7 +269,8 @@ class csstidy_optimise { ...@@ -269,7 +269,8 @@ class csstidy_optimise {
*/ */
public function compress_important(&$string) { public function compress_important(&$string) {
if ($this->parser->is_important($string)) { if ($this->parser->is_important($string)) {
$string = $this->parser->gvw_important($string) . '!important'; $important = $this->parser->get_cfg('space_before_important') ? ' !important' : '!important';
$string = $this->parser->gvw_important($string) . $important;
} }
return $string; return $string;
} }
...@@ -899,7 +900,7 @@ class csstidy_optimise { ...@@ -899,7 +900,7 @@ class csstidy_optimise {
$new_font_value = ''; $new_font_value = '';
$important = ''; $important = '';
// Skip if not font-family and font-size set // Skip if not font-family and font-size set
if (isset($input_css['font-family']) && isset($input_css['font-size'])) { if (isset($input_css['font-family']) && isset($input_css['font-size']) && $input_css['font-family'] != 'inherit') {
// fix several words in font-family - add quotes // fix several words in font-family - add quotes
if (isset($input_css['font-family'])) { if (isset($input_css['font-family'])) {
$families = explode(',', $input_css['font-family']); $families = explode(',', $input_css['font-family']);
......
...@@ -262,9 +262,11 @@ class csstidy_print { ...@@ -262,9 +262,11 @@ class csstidy_print {
case AT_END: case AT_END:
$out = & $output; $out = & $output;
$out .= $template[10] . str_replace("\n", "\n" . $template[10], $in_at_out); $in_at_out = str_replace("\n\n", "\r\n", $in_at_out); // don't fill empty lines
$in_at_out = str_replace("\n", "\n" . $template[10], $in_at_out);
$in_at_out = str_replace("\r\n", "\n\n", $in_at_out);
$out .= $template[10] . $in_at_out . $template[9];
$in_at_out = ''; $in_at_out = '';
$out .= $template[9];
break; break;
case COMMENT: case COMMENT:
...@@ -343,9 +345,9 @@ class csstidy_print { ...@@ -343,9 +345,9 @@ class csstidy_print {
foreach ($val as $selector => $vali) { foreach ($val as $selector => $vali) {
if ($sort_properties) if ($sort_properties)
ksort($vali); ksort($vali);
if (!empty($this->parser->comments[$medium.$selector])) { if (!empty($this->parser->comments[$medium.$selector])) {
$this->parser->_add_token(COMMENT, implode('. ', $this->parser->comments[$medium.$selector]), true); $this->parser->_add_token(COMMENT, implode('. ', $this->parser->comments[$medium.$selector]), true);
} }
$this->parser->_add_token(SEL_START, $selector, true); $this->parser->_add_token(SEL_START, $selector, true);
$invalid = array( $invalid = array(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment