Permalink
Browse files

Merge branch 'master' into 2.3

Conflicts:
	lib/Cake/View/Helper.php
  • Loading branch information...
2 parents 869d556 + 1f35d82 commit 739982addb8e38db9903adaf064496d888c21ce9 @markstory markstory committed Nov 26, 2012
View
10 lib/Cake/Controller/CakeErrorController.php
@@ -52,14 +52,12 @@ class CakeErrorController extends AppController {
*/
public function __construct($request = null, $response = null) {
parent::__construct($request, $response);
- if (
- count(Router::extensions()) &&
- !array_key_exists('RequestHandler', $this->components) &&
- !in_array('RequestHandler', $this->components, true)
+ $this->constructClasses();
+ if (count(Router::extensions()) &&
+ !$this->Components->attached('RequestHandler')
) {
- $this->components[] = 'RequestHandler';
+ $this->RequestHandler = $this->Components->load('RequestHandler');
}
- $this->constructClasses();
if ($this->Components->enabled('Auth')) {
$this->Components->disable('Auth');
}
View
1 lib/Cake/Controller/Component/EmailComponent.php
@@ -288,6 +288,7 @@ public function initialize(Controller $controller) {
public function send($content = null, $template = null, $layout = null) {
$lib = new CakeEmail();
$lib->charset = $this->charset;
+ $lib->headerCharset = $this->charset;
$lib->from($this->_formatAddresses((array)$this->from));
if (!empty($this->to)) {
View
3 lib/Cake/Test/Case/View/HelperTest.php
@@ -622,6 +622,9 @@ public function testAssetUrl() {
$result = $this->Helper->assetUrl('style', array('ext' => '.css'));
$this->assertEquals('style.css', $result);
+ $result = $this->Helper->assetUrl('dir/sub dir/my image', array('ext' => '.jpg'));
+ $this->assertEquals('dir/sub%20dir/my%20image.jpg', $result);
+
$result = $this->Helper->assetUrl('foo.jpg?one=two&three=four');
$this->assertEquals('foo.jpg?one=two&three=four', $result);
}
View
66 lib/Cake/View/Helper.php
@@ -295,38 +295,54 @@ public function assetUrl($path, $options = array()) {
if (is_array($path)) {
return $this->url($path, !empty($options['fullBase']));
}
- if (strpos($path, '://') === false) {
- if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
- list($plugin, $path) = $this->_View->pluginSplit($path, false);
- }
- if (!empty($options['pathPrefix']) && $path[0] !== '/') {
- $path = $options['pathPrefix'] . $path;
- }
- if (
- !empty($options['ext']) &&
- strpos($path, '?') === false &&
- substr($path, -strlen($options['ext'])) !== $options['ext']
- ) {
- $path .= $options['ext'];
- }
- if (isset($plugin)) {
- $path = Inflector::underscore($plugin) . '/' . $path;
- }
- $path = h($this->assetTimestamp($this->webroot($path)));
+ if (strpos($path, '://') !== false) {
+ return $path;
+ }
+ if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
+ list($plugin, $path) = $this->_View->pluginSplit($path, false);
+ }
+ if (!empty($options['pathPrefix']) && $path[0] !== '/') {
+ $path = $options['pathPrefix'] . $path;
+ }
+ if (
+ !empty($options['ext']) &&
+ strpos($path, '?') === false &&
+ substr($path, -strlen($options['ext'])) !== $options['ext']
+ ) {
+ $path .= $options['ext'];
+ }
+ if (isset($plugin)) {
+ $path = Inflector::underscore($plugin) . '/' . $path;
+ }
+ $path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path)));
- if (!empty($options['fullBase'])) {
- $base = $this->url('/', true);
- $len = strlen($this->request->webroot);
- if ($len) {
- $base = substr($base, 0, -$len);
- }
- $path = $base . $path;
+ if (!empty($options['fullBase'])) {
+ $base = $this->url('/', true);
+ $len = strlen($this->request->webroot);
+ if ($len) {
+ $base = substr($base, 0, -$len);
}
+ $path = $base . $path;
}
return $path;
}
/**
+ * Encodes a URL for use in HTML attributes.
+ *
+ * @param string $url The url to encode.
+ * @return string The url encoded for both URL & HTML contexts.
+ */
+ protected function _encodeUrl($url) {
+ $path = parse_url($url, PHP_URL_PATH);
+ $encoded = implode('/', array_map(
+ 'rawurlencode',
+ explode('/', $path)
+ ));
+ return h(str_replace($path, $encoded, $url));
+ }
+
+/**
* Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
* Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force'
* a timestamp will be added.

0 comments on commit 739982a

Please sign in to comment.