Problem/Motivation

All text that appears in a batch progress label is HTML escaped.

If Javascript is enabled, some HTML replacement happens (replacing the escaped HTML by unescaped HTML) so this is only a flash of about half a second. With JS disabled it happens in all steps.

For example, during the install step, the following text appears:

Initializing.<br>&nbsp;

Or during a test (JS disabled):

Proposed resolution

Output as #markup

Remaining tasks

Review patch.

User interface changes

No more double escaped markup showing up on install page or any batch pages.

API changes

None.

Data model changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Issue priority Major because affects installer which is the first thing people see, also this is child issue of #2297711: Fix HTML escaping due to Twig autoescape
Unfrozen changes Unfrozen because it only changes markup

Comments

mdrummond created an issue. See original summary.

rainbowarray’s picture

Priority: Normal » Major
Issue summary: View changes
StatusFileSize
new885.72 KB

Marking this as major which is maybe debatable, but this is one of the first things somebody sees when installing Drupal. It looks awful.

stefan.r’s picture

We probably shouldn't be autoescaping the HTML in the init message (the render array is in _batch_progress_page()):

    // Base and default properties for the batch set.
    $init = array(
      'sandbox' => array(),
      'results' => array(),
      'success' => FALSE,
      'start' => 0,
      'elapsed' => 0,
    );
    $defaults = array(
      'title' => t('Processing'),
      'init_message' => t('Initializing.'),
      'progress_message' => t('Completed @current of @total.'),
      'error_message' => t('An error has occurred.'),
      'css' => array(),
    );
    $batch_set = $init + $batch_definition + $defaults;

    // Tweak init_message to avoid the bottom of the page flickering down after
    // init phase.
    $batch_set['init_message'] .= '<br/>&nbsp;';
stefan.r’s picture

I can't reproduce this, the init message is unescaped for me on HEAD

rainbowarray’s picture

It's strange. It flashes unescaped but then switches to escaped during the install process. That makes me wonder if there's some sort of JS replacement going on.

stefan.r’s picture

StatusFileSize
new2.44 KB

I did manage to reproduce this in the end. There is actually some JS replacement in progress.js, where it does $('div.progress__description', this.element).html(message);. So it really is just a flash.

Here's an attempt at a patch...

rainbowarray’s picture

Status: Active » Needs review

I did not see the flash of special characters when I just tried an install with this patch. Nice work.

lauriii’s picture

+++ b/core/includes/batch.inc
@@ -150,6 +155,7 @@ function _batch_progress_page() {
+    $message = Xss::filter($message);

Nice to see it becoming a render array. Just curious, why do we need the $message to be escaped with Xss::filter? Isn't that the default behaviour of '#markup'?

stefan.r’s picture

Hmm you're right. #markup does admin XSS escaping which may be enough here assuming it's only admin users who ever see a progress bar. So maybe this could be a 1 line fix.

stefan.r’s picture

StatusFileSize
new450 bytes
stefan.r’s picture

joelpittet’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This could use some tests if possible but I think you can fairly assume that the message wouldn't need markup beyond what Xss admin filtering allows.

stefan.r’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.46 KB

Added a test

stefan.r’s picture

StatusFileSize
new3.49 KB
stefan.r’s picture

Issue summary: View changes
stefan.r’s picture

StatusFileSize
new1.17 KB
new3.79 KB
stefan.r’s picture

StatusFileSize
new361 bytes
new3.79 KB

reverting a change from that last patch

stefan.r’s picture

Issue summary: View changes
Related issues: +#2297711: Fix HTML escaping due to Twig autoescape
StatusFileSize
new57.68 KB

And if you disable javascript it's not just on the initial step, but everywhere:

stefan.r’s picture

Component: install system » batch system
stefan.r’s picture

Title: Markup and special characters display after the word Initializing during install step » Batch labels are double escaped
Issue summary: View changes
stefan.r’s picture

Title: Batch labels are double escaped » Batch labels are HTML escaped
Aki Tendo’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

stefan.r’s picture

Issue summary: View changes
lauriii’s picture

RTBC++

catch’s picture

Status: Reviewed & tested by the community » Needs review

The error handling also uses a <br /> tag in two different places - do you know whether this is also double escaped?

Also wondering whether there's something simple we can do to just ditch the hardcoded <br /> altogether.

stefan.r’s picture

Title: Batch labels are HTML escaped » All batch labels are HTML escaped
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new114.18 KB

We should ditch most <br />tags but for this one I'm not sure how or what it's purpose is. Some CSS trickery on the .progress__description may be possible, but IMO it's out of scope here as it's much less of an issue than the HTML escaping, where all labels are affected (not just the &nbsp;<br /> thing), and many of them have markup which also gets escaped (ie. #18).

As to the <br /> from the batch error handler, I tested and it's not double escaped:

The linebreak there is easier to get rid of, we can just wrap each error message in a block-level element instead.

The other bit is JS so unrelated.

stefan.r’s picture

Issue summary: View changes

Clarifying in the IS that this does not just affect the installer.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Makes sense. Opened #2555567: Remove hard-coded <br /> from batch API in case anyone wants to look at the break tags.

Committed/pushed to 8.0.x, thanks!

  • catch committed d9e895c on 8.0.x
    Issue #2548147 by stefan.r: All batch labels are HTML escaped
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.