Created a function for correctly converting characters to entities.

This commit is contained in:
Stefan Printezis committed 2016-11-10 23:58:02 +01:00
1 parent df0e112720
commit 6d1d46a258
2 files changed
+14 -6

No files matched your search

+4 -4
View File
@@ -485,7 +485,7 @@ class FormBuilder
// the element. Then we'll create the final textarea elements HTML for us. // the element. Then we'll create the final textarea elements HTML for us.
$options = $this->html->attributes($options); $options = $this->html->attributes($options);
return $this->toHtmlString('<textarea' . $options . '>' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '</textarea>'); return $this->toHtmlString('<textarea' . $options . '>' . $this->html->escapeAll($value). '</textarea>');
} }
/** /**
@@ -662,7 +662,7 @@ class FormBuilder
$html[] = $this->option($display, $value, $selected); $html[] = $this->option($display, $value, $selected);
} }
return $this->toHtmlString('<optgroup label="' . htmlentities($label, ENT_QUOTES, 'UTF-8') . '">' . implode('', $html) . '</optgroup>'); return $this->toHtmlString('<optgroup label="' . $this->html->escapeAll($label) . '">' . implode('', $html) . '</optgroup>');
} }
/** /**
@@ -680,7 +680,7 @@ class FormBuilder
$options = ['value' => $value, 'selected' => $selected]; $options = ['value' => $value, 'selected' => $selected];
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . htmlentities($display, ENT_QUOTES, 'UTF-8') . '</option>'); return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . $this->html->escapeAll($display) . '</option>');
} }
/** /**
@@ -698,7 +698,7 @@ class FormBuilder
$options = compact('selected'); $options = compact('selected');
$options['value'] = ''; $options['value'] = '';
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . htmlentities($display, ENT_QUOTES, 'UTF-8') . '</option>'); return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . $this->html->escapeAll($display) . '</option>');
} }
/** /**
+10 -2
View File
@@ -53,6 +53,14 @@ class HtmlBuilder
return htmlentities($value, ENT_QUOTES, 'UTF-8', false); 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. * Convert entities to HTML characters.
* *
@@ -387,7 +395,7 @@ class HtmlBuilder
if (is_array($value)) { if (is_array($value)) {
return $this->nestedListing($key, $type, $value); return $this->nestedListing($key, $type, $value);
} else { } else {
return '<li>' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '</li>'; return '<li>' . $this->html->escapeAll($value) . '</li>';
} }
} }
@@ -449,7 +457,7 @@ class HtmlBuilder
} }
if (! is_null($value)) { if (! is_null($value)) {
return $key . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '"'; return $key . '="' . $this->html->escapeAll($value) . '"';
} }
} }