Changeset 51809bd in github


Ignore:
Timestamp:
Jun 8, 2012 2:59:10 AM (12 months ago)
Author:
Aleksander Machniak <alec@…>
Branches:
release-0.8
Children:
a7d5e3e8
Parents:
49db523
git-author:
Aleksander Machniak <alec@…> (06/08/12 02:53:07)
git-committer:
Aleksander Machniak <alec@…> (06/08/12 02:59:10)
Message:

Fix handling of links with various URI schemes e.g. "skype:" (#1488106)
Fix handling of links inside PRE elements on html to text conversion
Fix indexing of links on html to text conversion

Conflicts:

CHANGELOG

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r0e58211 r51809bd  
    22=========================== 
    33 
     4- Fix handling of links with various URI schemes e.g. "skype:" (#1488106) 
     5- Fix handling of links inside PRE elements on html to text conversion 
     6- Fix indexing of links on html to text conversion 
    47- Decode header value in rcube_mime::get() by default (#1488511) 
    58- Fix errors with enabled PHP magic_quotes_sybase option (#1488506) 
  • program/lib/html2text.php

    rb4a0b92 r51809bd  
    250250     */ 
    251251    var $callback_search = array( 
    252         '/<(a) [^>]*href=("|\')([^"\']+)\2[^>]*>(.*?)<\/a>/i', 
    253                                                    // <a href=""> 
    254         '/<(h)[123456][^>]*>(.*?)<\/h[123456]>/i', // H1 - H3 
    255         '/<(b)[^>]*>(.*?)<\/b>/i',                 // <b> 
    256         '/<(strong)[^>]*>(.*?)<\/strong>/i',       // <strong> 
    257         '/<(th)[^>]*>(.*?)<\/th>/i',               // <th> and </th> 
     252        '/<(a) [^>]*href=("|\')([^"\']+)\2[^>]*>(.*?)<\/a>/i', // <a href=""> 
     253        '/<(h)[123456]( [^>]*)?>(.*?)<\/h[123456]>/i',         // h1 - h6 
     254        '/<(b)( [^>]*)?>(.*?)<\/b>/i',                         // <b> 
     255        '/<(strong)( [^>]*)?>(.*?)<\/strong>/i',               // <strong> 
     256        '/<(th)( [^>]*)?>(.*?)<\/th>/i',                       // <th> and </th> 
    258257    ); 
    259258 
     
    369368    { 
    370369        if ( $from_file && file_exists($source) ) { 
    371             $this->html = file_get_contents($source);  
     370            $this->html = file_get_contents($source); 
    372371        } 
    373372        else 
     
    561560 
    562561        // Ignored link types 
    563             if (preg_match('!^(javascript|mailto|#):!i', $link)) { 
     562            if (preg_match('!^(javascript:|mailto:|#)!i', $link)) { 
    564563                    return $display; 
    565564        } 
    566565 
    567             if (preg_match('!^(https?://)!i', $link)) { 
     566            if (preg_match('!^([a-z][a-z0-9.+-]+:)!i', $link)) { 
    568567            $url = $link; 
    569568        } 
     
    577576 
    578577        if (($index = array_search($url, $this->_link_list)) === false) { 
     578            $index = count($this->_link_list); 
    579579            $this->_link_list[] = $url; 
    580             $index = count($this->_link_list); 
    581580        } 
    582581 
     
    594593        // get the content of PRE element 
    595594        while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) { 
     595            $this->pre_content = $matches[1]; 
     596 
     597            // Run our defined tags search-and-replace with callback 
     598            $this->pre_content = preg_replace_callback($this->callback_search, 
     599                array('html2text', '_preg_callback'), $this->pre_content); 
     600 
    596601            // convert the content 
    597602            $this->pre_content = sprintf('<div><br>%s<br></div>', 
    598                 preg_replace($this->pre_search, $this->pre_replace, $matches[1])); 
     603                preg_replace($this->pre_search, $this->pre_replace, $this->pre_content)); 
     604 
    599605            // replace the content (use callback because content can contain $0 variable) 
    600             $text = preg_replace_callback('/<pre[^>]*>.*<\/pre>/ismU',  
     606            $text = preg_replace_callback('/<pre[^>]*>.*<\/pre>/ismU', 
    601607                array('html2text', '_preg_pre_callback'), $text, 1); 
     608 
    602609            // free memory 
    603610            $this->pre_content = ''; 
     
    672679        case 'b': 
    673680        case 'strong': 
    674             return $this->_toupper($matches[2]); 
     681            return $this->_toupper($matches[3]); 
    675682        case 'th': 
    676             return $this->_toupper("\t\t". $matches[2] ."\n"); 
     683            return $this->_toupper("\t\t". $matches[3] ."\n"); 
    677684        case 'h': 
    678             return $this->_toupper("\n\n". $matches[2] ."\n\n"); 
     685            return $this->_toupper("\n\n". $matches[3] ."\n\n"); 
    679686        case 'a': 
    680687            // Remove spaces in URL (#1487805) 
  • program/lib/washtml.php

    r02cf44e r51809bd  
    203203      $value = $node->getAttribute($key); 
    204204      if (isset($this->_html_attribs[$key]) || 
    205          ($key == 'href' && preg_match('!^(http:|https:|ftp:|mailto:|//|#).+!i', $value))) 
     205         ($key == 'href' && preg_match('!^([a-z][a-z0-9.+-]+:|//|#).+!i', $value))) 
    206206        $t .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; 
    207207      else if ($key == 'style' && ($style = $this->wash_style($value))) { 
Note: See TracChangeset for help on using the changeset viewer.