Commit 702e6a32 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1773891: Update csstidy to 1.5.7"

parents f76a72f3 79bac249
......@@ -2,10 +2,13 @@ CSSTidy in Mahara
=================
Website: https://github.com/Cerdic/CSSTidy
Version: 1.5.5
Version: 1.5.7
This library is used by clean_css, to strip out malicious CSS
Changes:
* Add new setting 'preserve_css_comment' and don't strip out CSS comments if it is set
* Add new setting 'preserve_css_comment' and don't strip out CSS comments if it is set. This is in class.csstidy.php.
Removed files we don't use:
/Docs and /testing folders
templates, travis, composer, .gitignore, css files, css_optimiser.php
\ No newline at end of file
CSSTidy
---
# CSSTidy [![Build Status](https://travis-ci.org/Cerdic/CSSTidy.svg?branch=master)](https://travis-ci.org/Cerdic/CSSTidy)
CSSTidy is a CSS minifier
v1.5.2
* v1.5.7 :
PHP 7 compatibility, composer update, Travis CI integration
* v1.5.6 :
fixes minor bugs, mainly on CSS3 properties/units
* v1.5.2 :
is PHP 5.4+ compliant, removes use of GLOBALS, fixes some bugs, integrates CSS3 units
and now available on https://packagist.org/packages/cerdic/css-tidy
v1.4 is the new version coming from master branch (corresponds to the initial trunk of svn repository) after beeing stabilized
v1.3 branch corresponds to the last stable relase published by the author.
* v1.4 : is the new version coming from master branch (corresponds to the initial trunk of svn repository) after beeing stabilized
* v1.3 branch corresponds to the last stable relase published by the author.<br/>
It integrates some bugfixes and a 1.3.1 version has been taged
Since the original project (http://csstidy.sourceforge.net/index.php) has been suspended
here is the import of https://csstidy.svn.sourceforge.net/svnroot/csstidy on 2010-11-14
......@@ -18,7 +19,7 @@ Only PHP version is here maintained
---
CSSTidy
## CSSTidy
Original Tracker :
http://sourceforge.net/tracker/?group_id=148404&atid=771415
......
......@@ -73,7 +73,7 @@ define('DEFAULT_AT', 41);
/**
* Contains a class for printing CSS code
*
* @version 1.0
* @version 1.1.0
*/
require('class.csstidy_print.php');
......@@ -94,7 +94,7 @@ require('class.csstidy_optimise.php');
* An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2006
* @version 1.5.5
* @version 1.5.7
*/
class csstidy {
......@@ -104,18 +104,6 @@ class csstidy {
* @access public
*/
public $css = array();
/**
* Saves the comments.
* @var array
* @access public
*/
public $comments = array();
/**
* Saves the current comments of the selectors
* @var array
* @access public
*/
public $cur_comments = array();
/**
* Saves the parsed CSS (raw)
* @var array
......@@ -159,7 +147,7 @@ class csstidy {
* @var string
* @access private
*/
public $version = '1.5.5';
public $version = '1.5.7';
/**
* Stores the settings
* @var array
......@@ -854,7 +842,6 @@ class csstidy {
}
}
$previous_property = $this->property;
$this->property = '';
$this->sub_value_arr = array();
$this->value = '';
......@@ -961,7 +948,7 @@ class csstidy {
if ($string{$i} === '*' && $string{$i + 1} === '/') {
$this->status = array_pop($this->from);
$i++;
if ($this->get_cfg('preserve_css_comment')) {
if ($this->get_cfg('preserve_css_comment')) {
$this->css_add_comment($this->at, $this->selector, $previous_property, $this->status, $cur_comment);
}
$this->_add_token(COMMENT, $cur_comment);
......@@ -1075,7 +1062,7 @@ class csstidy {
default:
break;
}
}
}
/**
* Adds a property with value to the existing CSS code
......@@ -1097,10 +1084,6 @@ class csstidy {
$this->css[$media][$selector][$property] = trim($new_val);
}
} else {
if (!empty($this->cur_comments)) {
$this->comments[$media.$selector] = $this->cur_comments;
$this->cur_comments = array();
}
$this->css[$media][$selector][$property] = trim($new_val);
}
}
......@@ -1125,7 +1108,7 @@ class csstidy {
return $media;
}
end($this->css);
list($at,) = each($this->css);
$at = key($this->css);
if ($at == $media) {
return $media;
}
......@@ -1164,7 +1147,7 @@ class csstidy {
// if last is the same, keep it
end($this->css[$media]);
list($sel,) = each($this->css[$media]);
$sel = key($this->css[$media]);
if ($sel == $selector) {
return $selector;
}
......
......@@ -74,7 +74,7 @@ class csstidy_optimise {
return;
}
if ($this->parser->get_cfg('merge_selectors') === 2) {
if ((int)$this->parser->get_cfg('merge_selectors') === 2) {
foreach ($this->css as $medium => $value) {
$this->merge_selectors($this->css[$medium]);
}
......@@ -400,9 +400,9 @@ class csstidy_optimise {
if ($number[1] == '' && in_array($this->property, $unit_values, true)) {
$number[1] = 'px';
}
} else {
$number[1] = '';
}
} elseif ($number[1] != 's' && $number[1] != 'ms') {
$number[1] = '';
}
$temp[$l] = $number[0] . $number[1];
}
......
......@@ -200,6 +200,12 @@ class csstidy_print {
$this->import[$i] = '"' . substr($this->import[$i], 4, -1) . '"';
$this->parser->log('Optimised @import : Removed "url("', 'Information');
}
else if (!preg_match('/^".+"$/',$this->import[$i])) {
// fixes a bug for @import ".." instead of the expected @import url("..")
// If it comes in due to @import ".." the "" will be missing and the output will become @import .. (which is an error)
$this->import[$i] = '"' . $this->import[$i] . '"';
}
$output .= $template[0] . '@import ' . $template[5] . $this->import[$i] . $template[6] . $template[13];
}
}
......@@ -241,17 +247,11 @@ class csstidy_print {
case VALUE:
$out .= $this->_htmlsp($token[1], $plain);
// If the next token is a comment, remove the '\n' from the template[6]
$valuetemplate = $template[6];
if ($this->_isnextcomment($key)) {
$valuetemplate = str_replace("\n", ' ', $template[6]);
}
if (!$this->_isnextcomment($key) && $this->_seeknocomment($key, 1) == SEL_END && $this->parser->get_cfg('remove_last_;')) {
$out .= str_replace(';', '', $valuetemplate);
}
else {
$out .= $valuetemplate;
}
if ($this->_seeknocomment($key, 1) == SEL_END && $this->parser->get_cfg('remove_last_;')) {
$out .= str_replace(';', '', $template[6]);
} else {
$out .= $template[6];
}
break;
case SEL_END:
......@@ -270,7 +270,7 @@ class csstidy_print {
break;
case COMMENT:
$out .= $template[11] . '/* ' . $this->_htmlsp($token[1], $plain) . ' */' . $template[12];
$out .= $template[11] . '/*' . $this->_htmlsp($token[1], $plain) . '*/' . $template[12];
break;
}
}
......@@ -286,17 +286,6 @@ class csstidy_print {
}
}
/**
* Checks if the next token is a comment
* @param integer $key current position
* @return bool
* @access private
* @version 1.0
*/
private function _isnextcomment($key) {
return (isset($this->tokens[$key + 1][0]) && $this->tokens[$key + 1][0] == COMMENT);
}
/**
* Gets the next token type which is $move away from $key, excluding comments
* @param integer $key current position
......@@ -345,9 +334,6 @@ class csstidy_print {
foreach ($val as $selector => $vali) {
if ($sort_properties)
ksort($vali);
if (!empty($this->parser->comments[$medium.$selector])) {
$this->parser->_add_token(COMMENT, implode('. ', $this->parser->comments[$medium.$selector]), true);
}
$this->parser->_add_token(SEL_START, $selector, true);
$invalid = array(
......@@ -364,9 +350,6 @@ class csstidy_print {
} else {
$this->parser->_add_token(PROPERTY, $property, true);
$this->parser->_add_token(VALUE, $valj, true);
if (!empty($this->parser->comments[$medium.$selector.$property])) {
$this->parser->_add_token(COMMENT, implode('. ', $this->parser->comments[$medium.$selector.$property]), true);
}
}
}
}
......
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