Changeset 5715 in subversion
- Timestamp:
- Jan 5, 2012 5:28:24 AM (17 months ago)
- Location:
- branches/release-0.7
- Files:
-
- 6 edited
-
CHANGELOG (modified) (1 diff)
-
program/include/main.inc (modified) (1 diff)
-
program/include/rcube_shared.inc (modified) (1 diff)
-
program/steps/mail/func.inc (modified) (1 diff)
-
tests/mailfunc.php (modified) (1 diff)
-
tests/src/htmlbase.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-0.7/CHANGELOG
r5712 r5715 2 2 =========================== 3 3 4 - Fix bug in handling of base href and inline content (#1488290) 4 5 - Fix SQL Error when saving a contact with many email addresses (#1488286) 5 6 - Fix strict email address searching if contact has more than one address -
branches/release-0.7/program/include/main.inc
r5591 r5715 2060 2060 public function callback($matches) 2061 2061 { 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; 2063 2124 } 2064 2125 } -
branches/release-0.7/program/include/rcube_shared.inc
r5274 r5715 162 162 163 163 return $str; 164 }165 166 /**167 * Convert paths like ../xxx to an absolute path using a base url168 *169 * @param string Relative path170 * @param string Base URL171 * @return string Absolute URL172 */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 URL179 if (preg_match('/^[fhtps]+:\/\//', $path))180 return $path;181 182 // cut base_url to the last directory183 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 absolute190 if ($path[0] == '/')191 $abs_path = $host_url.$path;192 else193 {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;210 164 } 211 165 -
branches/release-0.7/program/steps/mail/func.inc
r5601 r5715 1085 1085 if (preg_match('!(<base.*href=["\']?)([hftps]{3,5}://[a-z0-9/.%-]+)!i', $body, $regs)) { 1086 1086 $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); 1091 1088 } 1092 1089 1093 1090 return $body; 1094 1091 } 1092 1095 1093 1096 1094 /** -
branches/release-0.7/tests/mailfunc.php
r5636 r5715 167 167 $this->assertPattern('|src="http://alec\.pl/dir/img2\.gif"|', $html, "URI base resolving [2]"); 168 168 $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]"); 169 173 } 170 174 } -
branches/release-0.7/tests/src/htmlbase.txt
r4710 r5715 7 7 <img src="./img2.gif" /> 8 8 <img src="../img3.gif" /> 9 <img src="cid:theCID" /> 10 <img src="http://other.domain.tld/img3.gif" /> 9 11 </body> 10 12 </html>
Note: See TracChangeset
for help on using the changeset viewer.
