diff --git a/core/includes/common.inc b/core/includes/common.inc index 46a9356..703b259 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -29,6 +29,7 @@ use Drupal\Core\EventSubscriber\HtmlViewSubscriber; use Drupal\Core\Routing\GeneratorNotInitializedException; use Drupal\Core\Template\Attribute; +use Drupal\Core\Template\Markup; use Drupal\Core\Render\Element; use Drupal\Core\Session\AnonymousUserSession; @@ -3778,7 +3779,7 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { } $elements['#printed'] = TRUE; - return $elements['#markup']; + return new Markup($elements['#markup']); } /** @@ -3806,7 +3807,7 @@ function drupal_render_children(&$element, $children_keys = NULL) { $output .= drupal_render($element[$key]); } } - return $output; + return new Markup($output); } /** diff --git a/core/includes/form.inc b/core/includes/form.inc index 1c6af1b..bb5386f 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -14,6 +14,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Render\Element; use Drupal\Core\Template\Attribute; +use Drupal\Core\Template\Markup; use Drupal\Core\Utility\Color; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -1031,7 +1032,7 @@ function template_preprocess_fieldset(&$variables) { $variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL; $variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL; - $variables['children'] = $element['#children']; + $variables['children'] = new Markup($element['#children']); // Build legend properties. $variables['legend'] = array(); @@ -2689,7 +2690,7 @@ function template_preprocess_form(&$variables) { $element['#attributes']['accept-charset'] = "UTF-8"; } $variables['attributes'] = $element['#attributes']; - $variables['children'] = $element['#children']; + $variables['children'] = new Markup($element['#children']); } /** @@ -2905,7 +2906,7 @@ function template_preprocess_form_element(&$variables) { $variables['label'] = array('#theme' => 'form_element_label'); $variables['label'] += array_intersect_key($element, array_flip(array('#id', '#required', '#title', '#title_display'))); - $variables['children'] = $element['#children']; + $variables['children'] = new Markup($element['#children']); } /** diff --git a/core/includes/theme.inc b/core/includes/theme.inc index d45c2e5..3a3ce3d 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -17,6 +17,7 @@ use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\ExtensionNameLengthException; use Drupal\Core\Template\Attribute; +use Drupal\Core\Template\Markup; use Drupal\Core\Template\RenderWrapper; use Drupal\Core\Theme\ThemeSettings; use Drupal\Component\Utility\NestedArray; @@ -631,7 +632,8 @@ function _theme($hook, $variables = array()) { // restore path_to_theme() $theme_path = $temp; - return (string) $output; + + return new Markup($output); } /** @@ -1791,7 +1793,7 @@ function template_preprocess_container(&$variables) { $element['#attributes']['class'][] = 'form-wrapper'; } - $variables['children'] = $element['#children']; + $variables['children'] = new Markup($element['#children']); $variables['attributes'] = $element['#attributes']; } @@ -2078,7 +2080,7 @@ function template_preprocess_page(&$variables) { // Move some variables to the top level for themer convenience and template cleanliness. $variables['show_messages'] = $variables['page']['#show_messages']; - $variables['title'] = $variables['page']['#title']; + $variables['title'] = new Markup($variables['page']['#title']); foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) { if (!isset($variables['page'][$region_key])) { @@ -2108,7 +2110,7 @@ function template_preprocess_page(&$variables) { $variables['secondary_menu'] = theme_get_setting('features.secondary_menu') ? menu_secondary_menu() : array(); $variables['action_links'] = menu_get_local_actions(); $variables['tabs'] = menu_local_tabs(); - $variables['feed_icons'] = drupal_get_feeds(); + $variables['feed_icons'] = new Markup(drupal_get_feeds()); } else { $variables['main_menu'] = array(); @@ -2316,7 +2318,7 @@ function template_preprocess_install_page(&$variables) { */ function template_preprocess_region(&$variables) { // Create the $content variable that templates expect. - $variables['content'] = $variables['elements']['#children']; + $variables['content'] = new Markup($variables['elements']['#children']); $variables['region'] = $variables['elements']['#region']; $variables['attributes']['class'][] = 'region'; diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index 1cd43a3..b04f22a 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -118,7 +118,7 @@ public static function registerTwig(ContainerBuilder $container) { 'cache' => drupal_installation_attempted() ? FALSE : Settings::get('twig_cache', TRUE), // @todo Remove in followup issue // @see http://drupal.org/node/1712444. - 'autoescape' => FALSE, + 'autoescape' => TRUE, 'debug' => Settings::get('twig_debug', FALSE), 'auto_reload' => Settings::get('twig_auto_reload', NULL), )) diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index ead5d05..93e4340 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -31,7 +31,7 @@ * // Produces * @endcode */ -class Attribute implements \ArrayAccess, \IteratorAggregate { +class Attribute extends \Twig_Markup implements \ArrayAccess, \IteratorAggregate { /** * Stores the attribute data. diff --git a/core/lib/Drupal/Core/Template/Markup.php b/core/lib/Drupal/Core/Template/Markup.php new file mode 100644 index 0000000..fb53545 --- /dev/null +++ b/core/lib/Drupal/Core/Template/Markup.php @@ -0,0 +1,51 @@ +content = $content; + $this->charset = $charset; + } + + /** + * Implements the magic __toString() method. + */ + public function __toString() { + return (string) $this->render(); + } + + /** + * Renders the markup. + * + * @return string + * The results of the callback function. + */ + public function render() { + return $this->content; + } + +} diff --git a/core/lib/Drupal/Core/Template/RenderWrapper.php b/core/lib/Drupal/Core/Template/RenderWrapper.php index 7d7770d..58888e6 100644 --- a/core/lib/Drupal/Core/Template/RenderWrapper.php +++ b/core/lib/Drupal/Core/Template/RenderWrapper.php @@ -16,7 +16,7 @@ * $variables['scripts'] = new RenderWrapper('drupal_get_js', array('footer')); * @endcode */ -class RenderWrapper { +class RenderWrapper extends \Twig_Markup { /** * Stores the callback function to be called when rendered. @@ -52,7 +52,7 @@ public function __construct($callback, array $args = array()) { * Implements the magic __toString() method. */ public function __toString() { - return $this->render(); + return (string) $this->render(); } /** diff --git a/core/modules/book/templates/book-node-export-html.html.twig b/core/modules/book/templates/book-node-export-html.html.twig index 0efa9a7..57b5662 100644 --- a/core/modules/book/templates/book-node-export-html.html.twig +++ b/core/modules/book/templates/book-node-export-html.html.twig @@ -18,5 +18,5 @@

{{ title }}

{{ content }} - {{ children }} + {{ children|raw }}
diff --git a/core/modules/color/templates/color-scheme-form.html.twig b/core/modules/color/templates/color-scheme-form.html.twig index 6cfacbd..4d39743 100644 --- a/core/modules/color/templates/color-scheme-form.html.twig +++ b/core/modules/color/templates/color-scheme-form.html.twig @@ -22,5 +22,5 @@ {{ form }}

{{ 'Preview'|t }}

- {{ html_preview }} + {{ html_preview|raw }} diff --git a/core/modules/comment/templates/comment.html.twig b/core/modules/comment/templates/comment.html.twig index 5fca73b..aafa668 100644 --- a/core/modules/comment/templates/comment.html.twig +++ b/core/modules/comment/templates/comment.html.twig @@ -79,8 +79,8 @@ {{ title_suffix }} diff --git a/core/modules/filter/templates/filter-guidelines.html.twig b/core/modules/filter/templates/filter-guidelines.html.twig index 88a3b47..ecf9b94 100644 --- a/core/modules/filter/templates/filter-guidelines.html.twig +++ b/core/modules/filter/templates/filter-guidelines.html.twig @@ -20,6 +20,6 @@ */ #} -

{{ format.name|escape }}

+

{{ format.name }}

{{ tips }} diff --git a/core/modules/filter/templates/filter-tips.html.twig b/core/modules/filter/templates/filter-tips.html.twig index d8f70cb..27a3943 100644 --- a/core/modules/filter/templates/filter-tips.html.twig +++ b/core/modules/filter/templates/filter-tips.html.twig @@ -36,7 +36,7 @@ {% if tip.list|length %}
    {% for item in tip.list %} - {{ item.tip }} + {{ item.tip|raw }} {% endfor %}
{% endif %} diff --git a/core/modules/filter/templates/text-format-wrapper.html.twig b/core/modules/filter/templates/text-format-wrapper.html.twig index f453971..c657117 100644 --- a/core/modules/filter/templates/text-format-wrapper.html.twig +++ b/core/modules/filter/templates/text-format-wrapper.html.twig @@ -11,7 +11,7 @@ */ #}
- {{ children }} + {{ children|raw }} {% if description %}
{{ description }}
{% endif %} diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig index ae1162e..2b47e64 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -88,7 +88,7 @@ {% if display_submitted %}
{{ user_picture }} - +
{% endif %} diff --git a/core/modules/system/templates/breadcrumb.html.twig b/core/modules/system/templates/breadcrumb.html.twig index 5f322f9..d36a426 100644 --- a/core/modules/system/templates/breadcrumb.html.twig +++ b/core/modules/system/templates/breadcrumb.html.twig @@ -14,7 +14,7 @@

{{ 'You are here'|t }}

    {% for item in breadcrumb %} -
  1. {{ item }}
  2. +
  3. {{ item|raw }}
  4. {% endfor %}
diff --git a/core/modules/system/templates/checkboxes.html.twig b/core/modules/system/templates/checkboxes.html.twig index 00384d3..d38a918 100644 --- a/core/modules/system/templates/checkboxes.html.twig +++ b/core/modules/system/templates/checkboxes.html.twig @@ -14,4 +14,4 @@ @todo: remove this file once http://drupal.org/node/1819284 is resolved. This is identical to core/modules/system/templates/container.html.twig #} -{{ children }}
+{{ children|raw }} diff --git a/core/modules/system/templates/container.html.twig b/core/modules/system/templates/container.html.twig index a643e19..7800b64 100644 --- a/core/modules/system/templates/container.html.twig +++ b/core/modules/system/templates/container.html.twig @@ -15,4 +15,4 @@ * @ingroup themeable */ #} -{{ children }} +{{ children|raw }} diff --git a/core/modules/system/templates/datetime.html.twig b/core/modules/system/templates/datetime.html.twig index 25ef788..183b834 100644 --- a/core/modules/system/templates/datetime.html.twig +++ b/core/modules/system/templates/datetime.html.twig @@ -25,5 +25,4 @@ * @see http://www.w3.org/TR/html5-author/the-time-element.html#attr-time-datetime */ #} -{# @todo Revisit once http://drupal.org/node/1825952 is resolved. #} -{{ html ? text|raw : text|escape }} +{{ html ? text|raw : text }} diff --git a/core/modules/system/templates/details.html.twig b/core/modules/system/templates/details.html.twig index 17ea820..6283dc2 100644 --- a/core/modules/system/templates/details.html.twig +++ b/core/modules/system/templates/details.html.twig @@ -17,17 +17,17 @@ #} {%- if title -%} - {{ title }} + {{ title|raw }} {%- endif -%}
{%- if description -%} -
{{ description }}
+
{{ description|raw }}
{%- endif -%} {%- if children -%} - {{ children }} + {{ children|raw }} {%- endif -%} {%- if value -%} - {{ value }} + {{ value|raw }} {%- endif -%}
diff --git a/core/modules/system/templates/dropbutton-wrapper.html.twig b/core/modules/system/templates/dropbutton-wrapper.html.twig index ca0ff7e..d92bb6e 100644 --- a/core/modules/system/templates/dropbutton-wrapper.html.twig +++ b/core/modules/system/templates/dropbutton-wrapper.html.twig @@ -16,7 +16,7 @@ {% spaceless %}
- {{ children }} + {{ children|raw }}
{% endspaceless %} diff --git a/core/modules/system/templates/fieldset.html.twig b/core/modules/system/templates/fieldset.html.twig index 9e4fe68..f7fed3a 100644 --- a/core/modules/system/templates/fieldset.html.twig +++ b/core/modules/system/templates/fieldset.html.twig @@ -31,7 +31,7 @@ {% if prefix %} {{ prefix }} {% endif %} - {{ children }} + {{ children|raw }} {% if suffix %} {{ suffix }} {% endif %} diff --git a/core/modules/system/templates/form-element.html.twig b/core/modules/system/templates/form-element.html.twig index ea4d90f..bf9b76f 100644 --- a/core/modules/system/templates/form-element.html.twig +++ b/core/modules/system/templates/form-element.html.twig @@ -43,7 +43,7 @@ {% if prefix is not empty %} {{ prefix }} {% endif %} - {{ children }} + {{ children|raw }} {% if suffix is not empty %} {{ suffix }} {% endif %} @@ -52,7 +52,7 @@ {% endif %} {% if description.content %} - {{ description.content }} + {{ description.content|raw }} {% endif %} diff --git a/core/modules/system/templates/form.html.twig b/core/modules/system/templates/form.html.twig index b95fe71..7d5fdc2 100644 --- a/core/modules/system/templates/form.html.twig +++ b/core/modules/system/templates/form.html.twig @@ -12,4 +12,4 @@ * @ingroup themeable */ #} -
{{ children }}
+
{{ children|raw }}
diff --git a/core/modules/system/templates/item-list.html.twig b/core/modules/system/templates/item-list.html.twig index 34e1802..8e0a385 100644 --- a/core/modules/system/templates/item-list.html.twig +++ b/core/modules/system/templates/item-list.html.twig @@ -26,7 +26,7 @@ {%- if items -%} <{{ list_type }}{{ attributes }}> {%- for item in items -%} - {{ item.value }} + {{ item.value|raw }} {%- endfor -%} {%- else -%} diff --git a/core/modules/system/templates/radios.html.twig b/core/modules/system/templates/radios.html.twig index e397644..01725b7 100644 --- a/core/modules/system/templates/radios.html.twig +++ b/core/modules/system/templates/radios.html.twig @@ -12,4 +12,4 @@ * @ingroup themeable */ #} -{{ children }} +{{ children|raw }} diff --git a/core/modules/system/templates/select.html.twig b/core/modules/system/templates/select.html.twig index 21f32ac..6a24ffd 100644 --- a/core/modules/system/templates/select.html.twig +++ b/core/modules/system/templates/select.html.twig @@ -12,4 +12,4 @@ * @ingroup themeable */ #} -{{ options }} +{{ options|raw }} diff --git a/core/modules/system/templates/status-messages.html.twig b/core/modules/system/templates/status-messages.html.twig index 505eb20..e86df24 100644 --- a/core/modules/system/templates/status-messages.html.twig +++ b/core/modules/system/templates/status-messages.html.twig @@ -34,11 +34,11 @@ {% if messages|length > 1 %}
    {% for message in messages %} -
  • {{ message }}
  • +
  • {{ message|raw }}
  • {% endfor %}
{% else %} - {{ messages.0 }} + {{ messages.0|raw }} {% endif %} {% if type == 'error' %} diff --git a/core/modules/system/templates/vertical-tabs.html.twig b/core/modules/system/templates/vertical-tabs.html.twig index 5b7298b..98fe6d6 100644 --- a/core/modules/system/templates/vertical-tabs.html.twig +++ b/core/modules/system/templates/vertical-tabs.html.twig @@ -12,4 +12,4 @@ * @ingroup themeable */ #} -
{{ children }}
+
{{ children|Raw }}
diff --git a/core/modules/views/templates/views-view-grid.html.twig b/core/modules/views/templates/views-view-grid.html.twig index a5a813c..bfadb8e 100644 --- a/core/modules/views/templates/views-view-grid.html.twig +++ b/core/modules/views/templates/views-view-grid.html.twig @@ -31,7 +31,7 @@ {% for column in row.content %} - {{ column.content }} + {{ column.content|raw }} {% endfor %} @@ -41,7 +41,7 @@ {% for row in column.content %} - {{ row.content }} + {{ row.content|raw }} {% endfor %} diff --git a/core/modules/views/templates/views-view-table.html.twig b/core/modules/views/templates/views-view-table.html.twig index 6b0b26c..7b1f280 100644 --- a/core/modules/views/templates/views-view-table.html.twig +++ b/core/modules/views/templates/views-view-table.html.twig @@ -51,7 +51,7 @@ {% for column in header %} - {{ column.content }} + {{ column.content|raw }} {% endfor %} @@ -62,7 +62,7 @@ {% for column in row.columns %} - {{ column.content }} + {{ column.content|raw }} {% endfor %} diff --git a/core/modules/views_ui/templates/views-ui-container.html.twig b/core/modules/views_ui/templates/views-ui-container.html.twig index d45b158..3010a6c 100644 --- a/core/modules/views_ui/templates/views-ui-container.html.twig +++ b/core/modules/views_ui/templates/views-ui-container.html.twig @@ -12,4 +12,4 @@ * @ingroup themeable */ #} -{{ children }} +{{ children|raw }} diff --git a/core/themes/bartik/templates/comment.html.twig b/core/themes/bartik/templates/comment.html.twig index d2c4584..88e1db4 100644 --- a/core/themes/bartik/templates/comment.html.twig +++ b/core/themes/bartik/templates/comment.html.twig @@ -66,17 +66,17 @@
- {{ user_picture }} + {{ user_picture|raw }}
diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index 1595bf8..e5847cc 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -6,6 +6,7 @@ */ use Drupal\Core\Extension\Extension; +use Drupal\Core\Template\Markup; /** * Implements hook_theme(). @@ -138,7 +139,7 @@ function twig_render_var($arg) { if (is_object($arg)) { if (method_exists($arg, '__toString')) { - return (string) $arg; + return new $arg; } throw new Exception(t('Object of type "@class" cannot be printed.', array('@class' => get_class($arg)))); }