[PEAR-BUG] Bug #16544 [Com]: HTML_CSS undefined index on malformed input

[email protected] ("[email protected]")
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at http://pear.php.net/bugs/bug.php?id=16544&edit=1

 ID:               16544
 Comment by:       [email protected]
 Reported By:      brunobg at users dot sf dot net
 Summary:          HTML_CSS undefined index on malformed input
 Status:           Open
 Type:             Bug
 Package:          HTML_CSS
 Operating System: Linux
 Package Version:  1.5.4
 PHP Version:      5.2.5
 Roadmap Versions: 
 New Comment:

Looks like it does not support css with multiple rules on the same line
eg following breaks it:

$styles = array('
a {color: red;}
p {color: green;}
');

$css = new HTML_CSS(array('oneline' => true));
$css->parseData($styles);
$css->parseData(array($css->toString()));

Notice: Undefined index: p in Pear/HTML/CSS.php on line 2023


Previous Comments:
------------------------------------------------------------------------

[2011-06-30 05:35:54] tenitski

Your fix does not help with this sort of input:

#contentholder{border-color:#C32327;}.title{color:#C32327;}

It recognizes only the first rule.

------------------------------------------------------------------------

[2009-08-21 14:57:38] brunobg

Description:
------------
Malformed input generates an E_NOTICE exception with an undefined index.
Can be easily fixed by adding one line (at line 2022 of version 1.5.4),
marked with FIX below:

           $key = trim($keystr);
	    if (!array_key_exists($key, $atRulesMap)) continue; // FIX
            $parentAtRule = isset($atRulesMap[$key][$i])
                ? $atRulesMap[$key][$i] : $atRulesMap[$key][0];


Test script:
---------------
$parsed = new HTML_CSS();
$parsed->parseString('function whatever() {
	do_this();
}	');


Expected result:
----------------
No exception thrown.

Actual result:
--------------
Unknown error type: [8] Undefined index:
  Error in line 2023 of file /usr/lib/php/HTML/CSS.php

The exception happens on access to $atRulesMap[$key].

------------------------------------------------------------------------


-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=16544&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.