Browse Source

Fix up deprecations. Backport link behavior.

mscherer 6 years ago
parent
commit
a67c12f6e5

+ 11 - 3
src/View/Helper/HtmlHelper.php

@@ -277,7 +277,11 @@ class HtmlHelper extends Helper
         $out = null;
 
         if (isset($options['link'])) {
-            $options['link'] = $this->Url->assetUrl($options['link']);
+            if (is_array($options['link'])) {
+                $options['link'] = $this->Url->build($options['link']);
+            } else {
+                $options['link'] = $this->Url->assetUrl($options['link']);
+            }
             if (isset($options['rel']) && $options['rel'] === 'icon') {
                 $out = $this->formatTemplate('metalink', [
                     'url' => $options['link'],
@@ -850,14 +854,18 @@ class HtmlHelper extends Helper
      * - `fullBase` If true the src attribute will get a full address for the image file.
      * - `plugin` False value will prevent parsing path as a plugin
      *
-     * @param string|array $path Path to the image file, relative to the app/webroot/img/ directory.
+     * @param string|array $path Path to the image file, relative to the webroot/img/ directory.
      * @param array $options Array of HTML attributes. See above for special options.
      * @return string completed img tag
      * @link https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-images
      */
     public function image($path, array $options = [])
     {
-        $path = $this->Url->image($path, $options);
+        if (is_string($path)) {
+            $path = $this->Url->image($path, $options);
+        } else {
+            $path = $this->Url->build($path, $options);
+        }
         $options = array_diff_key($options, ['fullBase' => null, 'pathPrefix' => null]);
 
         if (!isset($options['alt'])) {

+ 5 - 15
src/View/Helper/UrlHelper.php

@@ -80,10 +80,6 @@ class UrlHelper extends Helper
      */
     public function image($path, array $options = [])
     {
-        if (is_array($path)) {
-            deprecationWarning('UrlHelper::image() in 4.x will not allow array of paths anymore. Use string here.');
-        }
-
         $pathPrefix = Configure::read('App.imageBaseUrl');
 
         return $this->assetUrl($path, $options + compact('pathPrefix'));
@@ -109,10 +105,6 @@ class UrlHelper extends Helper
      */
     public function css($path, array $options = [])
     {
-        if (is_array($path)) {
-            deprecationWarning('UrlHelper::css() in 4.x will not allow array of paths anymore. Use string here.');
-        }
-
         $pathPrefix = Configure::read('App.cssBaseUrl');
         $ext = '.css';
 
@@ -139,10 +131,6 @@ class UrlHelper extends Helper
      */
     public function script($path, array $options = [])
     {
-        if (is_array($path)) {
-            deprecationWarning('UrlHelper::script() in 4.x will not allow array of paths anymore. Use string here.');
-        }
-
         $pathPrefix = Configure::read('App.jsBaseUrl');
         $ext = '.js';
 
@@ -174,8 +162,6 @@ class UrlHelper extends Helper
     public function assetUrl($path, array $options = [])
     {
         if (is_array($path)) {
-            deprecationWarning('UrlHelper::assetUrl() in 4.x will not allow array of paths anymore. Use string here.');
-
             return $this->build($path, !empty($options['fullBase']));
         }
         // data URIs only require HTML escaping
@@ -250,11 +236,15 @@ class UrlHelper extends Helper
      */
     public function assetTimestamp($path, $timestamp = null)
     {
+        if (strpos($path, '?') !== false) {
+            return $path;
+        }
+
         if ($timestamp === null) {
             $timestamp = Configure::read('Asset.timestamp');
         }
         $timestampEnabled = $timestamp === 'force' || ($timestamp === true && Configure::read('debug'));
-        if ($timestampEnabled && strpos($path, '?') === false) {
+        if ($timestampEnabled) {
             $filepath = preg_replace(
                 '/^' . preg_quote($this->_View->getRequest()->getAttribute('webroot'), '/') . '/',
                 '',

+ 9 - 0
tests/TestCase/View/Helper/HtmlHelperTest.php

@@ -373,6 +373,15 @@ class HtmlHelperTest extends TestCase
         $result = $this->Html->image('//google.com/"><script>alert(1)</script>');
         $expected = ['img' => ['src' => '//google.com/&quot;&gt;&lt;script&gt;alert(1)&lt;/script&gt;', 'alt' => '']];
         $this->assertHtml($expected, $result);
+
+        $result = $this->Html->image([
+            'controller' => 'images',
+            'action' => 'display',
+            'test',
+            '?' => ['one' => 'two', 'three' => 'four'],
+        ]);
+        $expected = ['img' => ['src' => '/images/display/test?one=two&amp;three=four', 'alt' => '']];
+        $this->assertHtml($expected, $result);
     }
 
     /**