I just installed the module and opened /admin/settings/performance where I am getting the following error message (standard Drupal message area):

warning: Division by zero in /usr/local/www/apache22/data/drupal/sites/all/modules/csstidy/csstidy/class.csstidy_print.php on line 303.

Comments

philbar’s picture

Status: Active » Postponed (maintainer needs more info)

Is it possible you are trying to run CSSTidy on an empty stylesheet?

The PHP function resulting in the divide by zero error is strlen run on the original stylesheet which has not been processed by CSSTidy.

jaochoo’s picture

Well, I don't know.. ;-) I am using a Zen subtheme with a lot of CSS files; furthermore I guess there are many CSS files included by various contrib modules. So I really don't know if there is an empty stylesheet in all the CSS files. Actually, there shouldn't be, but I can't tell you. Anyways, IMHO this module should work even with empty stylesheets, otherwise every user would have to check all his stylesheets.

el7cosmos’s picture

i've got a lot of this error when i visit admin/build/modules ...

philbar’s picture

Well, I'm not really sure what could be going on.

The code causing this error is found in /csstidy/class.csstidy_print.php:

292 	 /**
293 	* Get compression ratio
294 	* @access public
295 	* @return float
296 	* @version 1.2
297 	*/
298 	function get_ratio()
299 	{
300 	if (!$this->output_css_plain) {
301 	$this->formatted();
302 	}
303 	return round((strlen($this->input_css) - strlen($this->output_css_plain)) / strlen($this->input_css), 3) * 100;
304 	} 

Specifically strlen($this->input_css) in returning 0, which causes the php error.

philbar’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Can you test the following fix?

Replace the code on line 292 of /csstidy/class.csstidy_print.php with this:

/**
 * Get compression ratio
 * @access public
 * @return float
 * @version 1.2
 */
function get_ratio()
{
    if (!$this->output_css_plain) {
        $this->formatted();
    }
    if (strlen($this->input_css) != 0) {
        return round((strlen($this->input_css) - strlen($this->output_css_plain)) / strlen($this->input_css), 3) * 100;
    }
}