Problem/Motivation

Steps to reproduce:
- Install standard and add an article with title containing some special characters like article's "title".
- View the article at /node/1 and see the window title says article's "title" | Site name.
- Reload the page and the title is article&039;s "title" | Site name.
- Edit the article at /node/1/edit and the title is double escaped as Edit Article article's "title" | Site name

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

olli’s picture

I think this bug was hidden before #2505989: Controllers render caching at the top level and setting a custom page title lose the title on render cache hits because node title was not cached. On render cache hit we get a title from cache that contains some html tags like <span data-quickedit-field-id="node/1/title/en/full" class="field field-node--title field-name-title field-type-string field-label-hidden">article&039;s &quot;title&quot;</span> and this string is marked as safe, but later the result of strip_tags() in template_preprocess_html() is not marked as safe.

olli’s picture

Title: Node's <title> double escaped on render cache hits » Page's <title> double escaped
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new536 bytes

This also affects <title> on node edit page.

borisson_’s picture

I can't reproduce this issue on current HEAD. Looks like I can, let's see if the patch solves the issue.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I can reproduce the issue and the patch solves the issue.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This needs tests.

olli’s picture

Issue tags: +Needs tests
+++ b/core/includes/theme.inc
@@ -1256,7 +1256,7 @@ function template_preprocess_html(&$variables) {
+      'title' => trim(Html::decodeEntities(strip_tags($variables['page']['#title']))),

Would SafeString::create(trim(strip_tags($variables['page']['#title']))) work better in case some other code marks an identical string (to the resulting 'title' here) as safe?

olli’s picture

#6 .. and do we still need ensure special characters are escaped with htmlspecialchars(Html::decodeEntities(..?

borisson_’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.12 KB
new1.64 KB

test-only should fail, that also acts as an interdiff.

dawehner’s picture

+++ b/core/includes/theme.inc
@@ -1256,7 +1256,7 @@ function template_preprocess_html(&$variables) {
-      'title' => trim(strip_tags($variables['page']['#title'])),
+      'title' => trim(Html::decodeEntities(strip_tags($variables['page']['#title']))),

Wait, so why is $variables['page']['#title'] escaped already? We should at least explain it, but this feels like the wrong fix to be honest. We should escape just when we output and this is it

The last submitted patch, 8: page_s_title_double-2531430-8-testonly.patch, failed testing.

borisson_’s picture

StatusFileSize
new1008 bytes
new1.58 KB

The previous patch did feel like a wrong approach, attached patch is also the wrong approach I think but it works just as well.

Status: Needs review » Needs work

The last submitted patch, 11: page_s_title_double-2531430-11.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.12 KB
new27.88 KB

The code in #2549393: Remove SafeMarkup::escape() and rely more on Twig autoescaping makes this issue pass, including the newly added test.

I attached a patch with #2549393: Remove SafeMarkup::escape() and rely more on Twig autoescaping and the test created in #8 (that should pass) and a patch with just the test (that should fail)

I think we could move the new testcoverage added here to #2549393: Remove SafeMarkup::escape() and rely more on Twig autoescaping and resolve this issue or keep this one as a followup to #2549393: Remove SafeMarkup::escape() and rely more on Twig autoescaping.

catch’s picture

Priority: Normal » Major

The last submitted patch, 13: testonly.patch, failed testing.

olli’s picture

Component: node system » theme system

#9

Wait, so why is $variables['page']['#title'] escaped already?

I think it is not already escaped but gets autoescaped (except on render cache miss it is marked safe).

Can we use decodeEntities and autoescaping here or should we use SafeString like #6?

olli’s picture

#16.1 doesn't make much sense.. I think we get the title from these:
EntityViewController::buildTitle()

$page['#title'] = $this->renderer->render($page[$label_field]);

NodeForm::form()

$form['#title'] = $this->t('<em>Edit @type</em> @title', array('@type' => node_get_type_label($node), '@title' => $node->label()));
wim leers’s picture

olli’s picture

This also affects _title_callback like BlockContentController::getAddFormTitle():

return $this->t('Add %type custom block', array('%type' => $block_content_type->label()));

Special characters in the label of block content type get double escaped.

ianthomas_uk’s picture

alexpott queued 13: testonly.patch for re-testing.

The last submitted patch, 13: testonly.patch, failed testing.

alexpott’s picture

lauriii’s picture

StatusFileSize
new54.57 KB

Lets see :P

Status: Needs review » Needs work

The last submitted patch, 24: 2531430-and-2560641.patch, failed testing.

alexpott’s picture

Status: Needs work » Closed (duplicate)

This test is now included as a part of #2560641-25: Remove all usages SafeMarkup::checkPlain() from render arrays - @borisson_ and @olli can you comment on that issue so you can get credit - thanks!