Show
Ignore:
Timestamp:
2008-03-19 20:50:24 (8 months ago)
Author:
wwalc
Message:

Fix for #1842: filename escape/encode problem causes XML error in file browser

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/filemanager/connectors/php/util.php

    r1629 r1736  
    3535} 
    3636 
     37function FindBadUtf8( $string ) 
     38{ 
     39        $regex = 
     40        '([\x00-\x7F]'. 
     41        '|[\xC2-\xDF][\x80-\xBF]'. 
     42        '|\xE0[\xA0-\xBF][\x80-\xBF]'. 
     43        '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'. 
     44        '|\xED[\x80-\x9F][\x80-\xBF]'. 
     45        '|\xF0[\x90-\xBF][\x80-\xBF]{2}'. 
     46        '|[\xF1-\xF3][\x80-\xBF]{3}'. 
     47        '|\xF4[\x80-\x8F][\x80-\xBF]{2}'. 
     48        '|(.{1}))'; 
     49 
     50        while (preg_match('/'.$regex.'/S', $string, $matches)) { 
     51                if ( isset($matches[2])) { 
     52                        return true; 
     53                } 
     54                $string = substr($string, strlen($matches[0])); 
     55        } 
     56 
     57        return false; 
     58} 
     59 
    3760function ConvertToXmlAttribute( $value ) 
    3861{ 
     
    4669        } 
    4770 
    48         if ( strtoupper( substr( $os, 0, 3 ) ) === 'WIN' ) 
     71        if ( strtoupper( substr( $os, 0, 3 ) ) === 'WIN' || FindBadUtf8( $value ) ) 
    4972        { 
    5073                return ( utf8_encode( htmlspecialchars( $value ) ) ) ;