Browse Source

Merge pull request #13520 from cakephp/issue-13518

Fix double escaping of URLs in PaginatorHelper::meta().
Mark Story 6 years ago
parent
commit
eca3ac14b8

+ 16 - 4
src/View/Helper/PaginatorHelper.php

@@ -1188,19 +1188,31 @@ class PaginatorHelper extends Helper
         $links = [];
 
         if ($options['prev'] && $this->hasPrev()) {
-            $links[] = $this->Html->meta('prev', $this->generateUrl(['page' => $params['page'] - 1], null, ['fullBase' => true]));
+            $links[] = $this->Html->meta(
+                'prev',
+                $this->generateUrl(['page' => $params['page'] - 1], null, ['escape' => false, 'fullBase' => true])
+            );
         }
 
         if ($options['next'] && $this->hasNext()) {
-            $links[] = $this->Html->meta('next', $this->generateUrl(['page' => $params['page'] + 1], null, ['fullBase' => true]));
+            $links[] = $this->Html->meta(
+                'next',
+                $this->generateUrl(['page' => $params['page'] + 1], null, ['escape' => false, 'fullBase' => true])
+            );
         }
 
         if ($options['first']) {
-            $links[] = $this->Html->meta('first', $this->generateUrl(['page' => 1], null, ['fullBase' => true]));
+            $links[] = $this->Html->meta(
+                'first',
+                $this->generateUrl(['page' => 1], null, ['escape' => false, 'fullBase' => true])
+            );
         }
 
         if ($options['last']) {
-            $links[] = $this->Html->meta('last', $this->generateUrl(['page' => $params['pageCount']], null, ['fullBase' => true]));
+            $links[] = $this->Html->meta(
+                'last',
+                $this->generateUrl(['page' => $params['pageCount']], null, ['escape' => false, 'fullBase' => true])
+            );
         }
 
         $out = implode($links);

+ 24 - 22
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -3016,38 +3016,38 @@ class PaginatorHelperTest extends TestCase
             // Verifies that no next and prev links are created for single page results.
             [1, false, false, 1, [], ''],
             // Verifies that first and last pages are created for single page results.
-            [1, false, false, 1, ['first' => true, 'last' => true], '<link href="http://localhost/index" rel="first"/>' .
-                '<link href="http://localhost/index" rel="last"/>'],
+            [1, false, false, 1, ['first' => true, 'last' => true], '<link href="http://localhost/index?foo=bar" rel="first"/>' .
+                '<link href="http://localhost/index?foo=bar" rel="last"/>'],
             // Verifies that first page is created for single page results.
-            [1, false, false, 1, ['first' => true], '<link href="http://localhost/index" rel="first"/>'],
+            [1, false, false, 1, ['first' => true], '<link href="http://localhost/index?foo=bar" rel="first"/>'],
             // Verifies that last page is created for single page results.
-            [1, false, false, 1, ['last' => true], '<link href="http://localhost/index" rel="last"/>'],
+            [1, false, false, 1, ['last' => true], '<link href="http://localhost/index?foo=bar" rel="last"/>'],
             // Verifies that page 1 only has a next link.
-            [1, false, true, 2, [], '<link href="http://localhost/index?page=2" rel="next"/>'],
+            [1, false, true, 2, [], '<link href="http://localhost/index?foo=bar&amp;page=2" rel="next"/>'],
             // Verifies that page 1 only has next, first and last link.
-            [1, false, true, 2, ['first' => true, 'last' => true], '<link href="http://localhost/index?page=2" rel="next"/>' .
-                '<link href="http://localhost/index" rel="first"/>' .
-                '<link href="http://localhost/index?page=2" rel="last"/>'],
+            [1, false, true, 2, ['first' => true, 'last' => true], '<link href="http://localhost/index?foo=bar&amp;page=2" rel="next"/>' .
+                '<link href="http://localhost/index?foo=bar" rel="first"/>' .
+                '<link href="http://localhost/index?foo=bar&amp;page=2" rel="last"/>'],
             // Verifies that page 1 only has next and first link.
-            [1, false, true, 2, ['first' => true], '<link href="http://localhost/index?page=2" rel="next"/>' .
-                '<link href="http://localhost/index" rel="first"/>'],
+            [1, false, true, 2, ['first' => true], '<link href="http://localhost/index?foo=bar&amp;page=2" rel="next"/>' .
+                '<link href="http://localhost/index?foo=bar" rel="first"/>'],
             // Verifies that page 1 only has next and last link.
-            [1, false, true, 2, ['last' => true], '<link href="http://localhost/index?page=2" rel="next"/>' .
-                '<link href="http://localhost/index?page=2" rel="last"/>'],
+            [1, false, true, 2, ['last' => true], '<link href="http://localhost/index?foo=bar&amp;page=2" rel="next"/>' .
+                '<link href="http://localhost/index?foo=bar&amp;page=2" rel="last"/>'],
             // Verifies that the last page only has a prev link.
-            [2, true, false, 2, [], '<link href="http://localhost/index" rel="prev"/>'],
+            [2, true, false, 2, [], '<link href="http://localhost/index?foo=bar" rel="prev"/>'],
             // Verifies that the last page only has a prev, first and last link.
-            [2, true, false, 2, ['first' => true, 'last' => true], '<link href="http://localhost/index" rel="prev"/>' .
-                '<link href="http://localhost/index" rel="first"/>' .
-                '<link href="http://localhost/index?page=2" rel="last"/>'],
+            [2, true, false, 2, ['first' => true, 'last' => true], '<link href="http://localhost/index?foo=bar" rel="prev"/>' .
+                '<link href="http://localhost/index?foo=bar" rel="first"/>' .
+                '<link href="http://localhost/index?foo=bar&amp;page=2" rel="last"/>'],
             // Verifies that a page in the middle has both links.
-            [5, true, true, 10, [], '<link href="http://localhost/index?page=4" rel="prev"/>' .
-                '<link href="http://localhost/index?page=6" rel="next"/>'],
+            [5, true, true, 10, [], '<link href="http://localhost/index?foo=bar&amp;page=4" rel="prev"/>' .
+                '<link href="http://localhost/index?foo=bar&amp;page=6" rel="next"/>'],
             // Verifies that a page in the middle has both links.
-            [5, true, true, 10, ['first' => true, 'last' => true], '<link href="http://localhost/index?page=4" rel="prev"/>' .
-                '<link href="http://localhost/index?page=6" rel="next"/>' .
-                '<link href="http://localhost/index" rel="first"/>' .
-                '<link href="http://localhost/index?page=10" rel="last"/>']
+            [5, true, true, 10, ['first' => true, 'last' => true], '<link href="http://localhost/index?foo=bar&amp;page=4" rel="prev"/>' .
+                '<link href="http://localhost/index?foo=bar&amp;page=6" rel="next"/>' .
+                '<link href="http://localhost/index?foo=bar" rel="first"/>' .
+                '<link href="http://localhost/index?foo=bar&amp;page=10" rel="last"/>']
         ];
     }
 
@@ -3071,6 +3071,8 @@ class PaginatorHelperTest extends TestCase
             ]
         ]));
 
+        $this->Paginator->options(['url' => ['?' => ['foo' => 'bar']]]);
+
         $result = $this->Paginator->meta($options);
         $this->assertSame($expected, $result);