From 6d1d46a258d3cd662f36e8f956634950b4517eeb Mon Sep 17 00:00:00 2001 From: Stefan Printezis Date: Thu, 10 Nov 2016 23:58:02 +0100 Subject: [PATCH] Created a function for correctly converting characters to entities. --- src/FormBuilder.php | 8 ++++---- src/HtmlBuilder.php | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 0e03984..9b2fe1c 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -485,7 +485,7 @@ class FormBuilder // the element. Then we'll create the final textarea elements HTML for us. $options = $this->html->attributes($options); - return $this->toHtmlString('' . htmlentities($value, ENT_QUOTES, 'UTF-8') . ''); + return $this->toHtmlString('' . $this->html->escapeAll($value). ''); } /** @@ -662,7 +662,7 @@ class FormBuilder $html[] = $this->option($display, $value, $selected); } - return $this->toHtmlString('' . implode('', $html) . ''); + return $this->toHtmlString('' . implode('', $html) . ''); } /** @@ -680,7 +680,7 @@ class FormBuilder $options = ['value' => $value, 'selected' => $selected]; - return $this->toHtmlString('html->attributes($options) . '>' . htmlentities($display, ENT_QUOTES, 'UTF-8') . ''); + return $this->toHtmlString('html->attributes($options) . '>' . $this->html->escapeAll($display) . ''); } /** @@ -698,7 +698,7 @@ class FormBuilder $options = compact('selected'); $options['value'] = ''; - return $this->toHtmlString('html->attributes($options) . '>' . htmlentities($display, ENT_QUOTES, 'UTF-8') . ''); + return $this->toHtmlString('html->attributes($options) . '>' . $this->html->escapeAll($display) . ''); } /** diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index b42ce53..cd504f8 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -53,6 +53,14 @@ class HtmlBuilder return htmlentities($value, ENT_QUOTES, 'UTF-8', false); } + /** + * Convert all applicable characters to HTML entities. + */ + public function escapeAll($value) + { + return htmlentities($value, ENT_QUOTES, 'UTF-8'); + } + /** * Convert entities to HTML characters. * @@ -387,7 +395,7 @@ class HtmlBuilder if (is_array($value)) { return $this->nestedListing($key, $type, $value); } else { - return '
  • ' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '
  • '; + return '
  • ' . $this->html->escapeAll($value) . '
  • '; } } @@ -449,7 +457,7 @@ class HtmlBuilder } if (! is_null($value)) { - return $key . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '"'; + return $key . '="' . $this->html->escapeAll($value) . '"'; } }