Changeset 5715 in subversion


Ignore:
Timestamp:
Jan 5, 2012 5:28:24 AM (17 months ago)
Author:
alec
Message:
Location:
branches/release-0.7
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/release-0.7/CHANGELOG

    r5712 r5715  
    22=========================== 
    33 
     4- Fix bug in handling of base href and inline content (#1488290) 
    45- Fix SQL Error when saving a contact with many email addresses (#1488286) 
    56- Fix strict email address searching if contact has more than one address 
  • branches/release-0.7/program/include/main.inc

    r5591 r5715  
    20602060  public function callback($matches) 
    20612061  { 
    2062     return $matches[1] . '="' . make_absolute_url($matches[3], $this->base_url) . '"'; 
     2062    return $matches[1] . '="' . self::absolute_url($matches[3], $this->base_url) . '"'; 
     2063  } 
     2064 
     2065  public function replace($body) 
     2066  { 
     2067    return preg_replace_callback(array( 
     2068      '/(src|background|href)=(["\']?)([^"\'\s]+)(\2|\s|>)/Ui', 
     2069      '/(url\s*\()(["\']?)([^"\'\)\s]+)(\2)\)/Ui', 
     2070      ), 
     2071      array($this, 'callback'), $body); 
     2072  } 
     2073 
     2074  /** 
     2075   * Convert paths like ../xxx to an absolute path using a base url 
     2076   * 
     2077   * @param string $path     Relative path 
     2078   * @param string $base_url Base URL 
     2079   * 
     2080   * @return string Absolute URL 
     2081   */ 
     2082  public static function absolute_url($path, $base_url) 
     2083  { 
     2084    $host_url = $base_url; 
     2085    $abs_path = $path; 
     2086 
     2087    // check if path is an absolute URL 
     2088    if (preg_match('/^[fhtps]+:\/\//', $path)) { 
     2089      return $path; 
     2090    } 
     2091 
     2092    // check if path is a content-id scheme 
     2093    if (strpos($path, 'cid:') === 0) { 
     2094      return $path; 
     2095    } 
     2096 
     2097    // cut base_url to the last directory 
     2098    if (strrpos($base_url, '/') > 7) { 
     2099      $host_url = substr($base_url, 0, strpos($base_url, '/', 7)); 
     2100      $base_url = substr($base_url, 0, strrpos($base_url, '/')); 
     2101    } 
     2102 
     2103    // $path is absolute 
     2104    if ($path[0] == '/') { 
     2105      $abs_path = $host_url.$path; 
     2106    } 
     2107    else { 
     2108      // strip './' because its the same as '' 
     2109      $path = preg_replace('/^\.\//', '', $path); 
     2110 
     2111      if (preg_match_all('/\.\.\//', $path, $matches, PREG_SET_ORDER)) { 
     2112        foreach ($matches as $a_match) { 
     2113          if (strrpos($base_url, '/')) { 
     2114            $base_url = substr($base_url, 0, strrpos($base_url, '/')); 
     2115          } 
     2116          $path = substr($path, 3); 
     2117        } 
     2118      } 
     2119 
     2120      $abs_path = $base_url.'/'.$path; 
     2121    } 
     2122 
     2123    return $abs_path; 
    20632124  } 
    20642125} 
  • branches/release-0.7/program/include/rcube_shared.inc

    r5274 r5715  
    162162 
    163163  return $str; 
    164 } 
    165  
    166 /** 
    167  * Convert paths like ../xxx to an absolute path using a base url 
    168  * 
    169  * @param string Relative path 
    170  * @param string Base URL 
    171  * @return string Absolute URL 
    172  */ 
    173 function make_absolute_url($path, $base_url) 
    174 { 
    175   $host_url = $base_url; 
    176   $abs_path = $path; 
    177  
    178   // check if path is an absolute URL 
    179   if (preg_match('/^[fhtps]+:\/\//', $path)) 
    180     return $path; 
    181  
    182   // cut base_url to the last directory 
    183   if (strrpos($base_url, '/')>7) 
    184   { 
    185     $host_url = substr($base_url, 0, strpos($base_url, '/', 7)); 
    186     $base_url = substr($base_url, 0, strrpos($base_url, '/')); 
    187   } 
    188  
    189   // $path is absolute 
    190   if ($path[0] == '/') 
    191     $abs_path = $host_url.$path; 
    192   else 
    193   { 
    194     // strip './' because its the same as '' 
    195     $path = preg_replace('/^\.\//', '', $path); 
    196  
    197     if (preg_match_all('/\.\.\//', $path, $matches, PREG_SET_ORDER)) 
    198       foreach ($matches as $a_match) 
    199       { 
    200         if (strrpos($base_url, '/')) 
    201           $base_url = substr($base_url, 0, strrpos($base_url, '/')); 
    202  
    203         $path = substr($path, 3); 
    204       } 
    205  
    206     $abs_path = $base_url.'/'.$path; 
    207   } 
    208  
    209   return $abs_path; 
    210164} 
    211165 
  • branches/release-0.7/program/steps/mail/func.inc

    r5601 r5715  
    10851085  if (preg_match('!(<base.*href=["\']?)([hftps]{3,5}://[a-z0-9/.%-]+)!i', $body, $regs)) { 
    10861086    $replacer = new rcube_base_replacer($regs[2]); 
    1087  
    1088     // replace all relative paths 
    1089     $body = preg_replace_callback('/(src|background|href)=(["\']?)([^"\'\s]+)(\2|\s|>)/Ui', array($replacer, 'callback'), $body); 
    1090     $body = preg_replace_callback('/(url\s*\()(["\']?)([^"\'\)\s]+)(\2)\)/Ui', array($replacer, 'callback'), $body); 
     1087    $body     = $replacer->replace($body); 
    10911088  } 
    10921089 
    10931090  return $body; 
    10941091} 
     1092 
    10951093 
    10961094/** 
  • branches/release-0.7/tests/mailfunc.php

    r5636 r5715  
    167167    $this->assertPattern('|src="http://alec\.pl/dir/img2\.gif"|', $html, "URI base resolving [2]"); 
    168168    $this->assertPattern('|src="http://alec\.pl/img3\.gif"|', $html, "URI base resolving [3]"); 
     169 
     170    // base resolving exceptions 
     171    $this->assertPattern('|src="cid:theCID"|', $html, "URI base resolving exception [1]"); 
     172    $this->assertPattern('|src="http://other\.domain\.tld/img3\.gif"|', $html, "URI base resolving exception [2]"); 
    169173  } 
    170174} 
  • branches/release-0.7/tests/src/htmlbase.txt

    r4710 r5715  
    77<img src="./img2.gif" /> 
    88<img src="../img3.gif" /> 
     9<img src="cid:theCID" /> 
     10<img src="http://other.domain.tld/img3.gif" /> 
    911</body> 
    1012</html> 
Note: See TracChangeset for help on using the changeset viewer.