PHPIDS
Current file: /home/mario/workspace/php-ids.org/trunk/lib/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/HTML/Length.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1
35.71 %35.71%
35.71% 5 / 14
 
HTMLPurifier_AttrDef_HTML_Length
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1
35.71 %35.71%
35.71% 5 / 14
 public function validate($string, $config, $context)
100.00 %100.00%
100.00% 1 / 1
30.77 %30.77%
30.77% 4 / 13


       1                 : <?php                                                                          
       2                 :                                                                                
       3                 : /**                                                                            
       4                 :  * Validates the HTML type length (not to be confused with CSS's length).      
       5                 :  *                                                                             
       6                 :  * This accepts integer pixels or percentages as lengths for certain           
       7                 :  * HTML attributes.                                                            
       8                 :  */                                                                            
       9                 :                                                                                
      10               1 : class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels
      11                 : {                                                                              
      12                 :                                                                                
      13                 :     public function validate($string, $config, $context) {                     
      14                 :                                                                                
      15               2 :         $string = trim($string);                                               
      16               2 :         if ($string === '') return false;                                      
      17                 :                                                                                
      18               2 :         $parent_result = parent::validate($string, $config, $context);         
      19               2 :         if ($parent_result !== false) return $parent_result;                   
      20                 :                                                                                
      21               0 :         $length = strlen($string);                                             
      22               0 :         $last_char = $string[$length - 1];                                     
      23                 :                                                                                
      24               0 :         if ($last_char !== '%') return false;                                  
      25                 :                                                                                
      26               0 :         $points = substr($string, 0, $length - 1);                             
      27                 :                                                                                
      28               0 :         if (!is_numeric($points)) return false;                                
      29                 :                                                                                
      30               0 :         $points = (int) $points;                                               
      31                 :                                                                                
      32               0 :         if ($points < 0) return '0%';                                          
      33               0 :         if ($points > 100) return '100%';                                      
      34                 :                                                                                
      35               0 :         return ((string) $points) . '%';                                       
      36                 :                                                                                
      37                 :     }                                                                          
      38                 :                                                                                
      39                 : }                                                                              
      40                 :                                                                                

Generated by PHPUnit 3.3.1 and Xdebug 2.0.2 at Thu Sep 25 18:42:10 CEST 2008.