Skip to content

Commit

Permalink
Merge branch 'master' into 2.3
Browse files Browse the repository at this point in the history
Conflicts:
	lib/Cake/View/Helper.php
  • Loading branch information
markstory committed Nov 26, 2012
2 parents 869d556 + 1f35d82 commit 739982a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
10 changes: 4 additions & 6 deletions lib/Cake/Controller/CakeErrorController.php
Expand Up @@ -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');
}
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Controller/Component/EmailComponent.php
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Cake/Test/Case/View/HelperTest.php
Expand Up @@ -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);
}
Expand Down
66 changes: 41 additions & 25 deletions lib/Cake/View/Helper.php
Expand Up @@ -295,37 +295,53 @@ 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'
Expand Down

0 comments on commit 739982a

Please sign in to comment.