function OutputRules::escape
Escape test.
According to the html5 spec section 8.3 Serializing HTML fragments, text within tags that are not style, script, xmp, iframe, noembed, and noframes need to be properly escaped.
The & should be converted to &, no breaking space unicode characters converted to , when in attribute mode the " should be converted to ", and when not in attribute mode the < and > should be converted to < and >.
Parameters
string $text Text to escape.:
bool $attribute True if we are escaping an attrubute, false otherwise.:
See also
http://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#escapingString
3 calls to OutputRules::escape()
- HtmlSerializerRules::escape in core/
lib/ Drupal/ Component/ Utility/ HtmlSerializerRules.php - Escape test.
- HtmlSerializerRules::escape in core/
lib/ Drupal/ Component/ Utility/ HtmlSerializerRules.php - Escape test.
- OutputRules::enc in vendor/
masterminds/ html5/ src/ HTML5/ Serializer/ OutputRules.php - Encode text.
1 method overrides OutputRules::escape()
- HtmlSerializerRules::escape in core/
lib/ Drupal/ Component/ Utility/ HtmlSerializerRules.php - Escape test.
File
-
vendor/
masterminds/ html5/ src/ HTML5/ Serializer/ OutputRules.php, line 531
Class
- OutputRules
- Generate the output html5 based on element rules.
Namespace
Masterminds\HTML5\SerializerCode
protected function escape($text, $attribute = false) {
// Not using htmlspecialchars because, while it does escaping, it doesn't
// match the requirements of section 8.5. For example, it doesn't handle
// non-breaking spaces.
if ($attribute) {
$replace = array(
'"' => '"',
'&' => '&',
" " => ' ',
);
}
else {
$replace = array(
'<' => '<',
'>' => '>',
'&' => '&',
" " => ' ',
);
}
return strtr($text, $replace);
}