|
3 | 3 | namespace Illuminate\Pagination;
|
4 | 4 |
|
5 | 5 | use Closure;
|
| 6 | +use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString; |
6 | 7 | use Illuminate\Contracts\Support\Htmlable;
|
7 | 8 | use Illuminate\Support\Arr;
|
8 | 9 | use Illuminate\Support\Collection;
|
|
18 | 19 | *
|
19 | 20 | * @mixin \Illuminate\Support\Collection<TKey, TValue>
|
20 | 21 | */
|
21 |
| -abstract class AbstractPaginator implements Htmlable, Stringable |
| 22 | +abstract class AbstractPaginator implements CanBeEscapedWhenCastToString, Htmlable, Stringable |
22 | 23 | {
|
23 | 24 | use ForwardsCalls, Tappable;
|
24 | 25 |
|
@@ -71,6 +72,13 @@ abstract class AbstractPaginator implements Htmlable, Stringable
|
71 | 72 | */
|
72 | 73 | protected $pageName = 'page';
|
73 | 74 |
|
| 75 | + /** |
| 76 | + * Indicates that the paginator's string representation should be escaped when __toString is invoked. |
| 77 | + * |
| 78 | + * @var bool |
| 79 | + */ |
| 80 | + protected $escapeWhenCastingToString = false; |
| 81 | + |
74 | 82 | /**
|
75 | 83 | * The number of links to display on each side of current page link.
|
76 | 84 | *
|
@@ -797,6 +805,21 @@ public function __call($method, $parameters)
|
797 | 805 | */
|
798 | 806 | public function __toString()
|
799 | 807 | {
|
800 |
| - return (string) $this->render(); |
| 808 | + return $this->escapeWhenCastingToString |
| 809 | + ? e((string) $this->render()) |
| 810 | + : (string) $this->render(); |
| 811 | + } |
| 812 | + |
| 813 | + /** |
| 814 | + * Indicate that the paginator's string representation should be escaped when __toString is invoked. |
| 815 | + * |
| 816 | + * @param bool $escape |
| 817 | + * @return $this |
| 818 | + */ |
| 819 | + public function escapeWhenCastingToString($escape = true) |
| 820 | + { |
| 821 | + $this->escapeWhenCastingToString = $escape; |
| 822 | + |
| 823 | + return $this; |
801 | 824 | }
|
802 | 825 | }
|
0 commit comments