We added this issue a few weeks ago, it's happening since RC1:

It's still happening on RC3.

Steps to Reproduce

  1. First you go to Administration->Views->edit one of your views (Screen Shot 2015-11-06 at 3.19.34 PM.png)
  2. Then under "Fields" you click to edit one of the fields (Screen Shot 2015-11-06 at 3.20.12 PM.png)
  3. Under "No Result Behavior" enter HTML (Screen Shot 2015-11-06 at 3.20.28 PM.png)
  4. And in the preview you'll see the tags and rendered as plain text (Screen Shot 2015-11-06 at 3.21.08 PM.png)

Original Report

#2585205: No results behavior showing html markup code

When adding a "NO RESULTS BEHAVIOR" for a field in a view, the view is showing the HTML markup code instead of rendering it.

We are using:
Drupal core 8.0.0-rc1
Standard Profile

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gceja created an issue. See original summary.

marcingy’s picture

Version: 8.0.0-rc3 » 8.0.x-dev
Priority: Critical » Major

This isn't critical and exact steps to reproduce the issue would be super helpful

jclopez’s picture

The same it's happening on my end

Ones I create a view block and on any field I set the "No results behavior" with HTML
On the render I can see the tags and everything as plain text, according to the help text for that field "You may include HTML" so clearly something is broken.

cilefen’s picture

There is really no such thing as Views 8.x, it is in core. That is probably why this issue was ignored #2585205: No results behavior showing html markup code

cilefen’s picture

Title: Views - Showing html code as plain text instead of rendering it » Views - "No Results Behavior" showing html code as plain text instead of rendering it
Issue summary: View changes
cilefen’s picture

What kind of "No results behavior" field are you using? Is it "Text area"?
Could add the steps to reproduce to the summary please?

cilefen’s picture

I just tested with HEAD and HTML in a "Text area" and the HTML was rendered, not escaped.

jclopez’s picture

Ok, here are the steps:
First you go to Administration->Views->edit one of your views (Screen Shot 2015-11-06 at 3.19.34 PM.png)
Then under "Fields" you click to edit one of the fields (Screen Shot 2015-11-06 at 3.20.12 PM.png)
Under "No Result Behavior" enter HTML (Screen Shot 2015-11-06 at 3.20.28 PM.png)
And in the preview you'll see the tags and rendered as plain text (Screen Shot 2015-11-06 at 3.21.08 PM.png)

Here are the screenshots:

Thank you

cilefen’s picture

Title: Views - "No Results Behavior" showing html code as plain text instead of rendering it » Views - "No Results Behavior" for individual fields escapes HTML

Thank you! Could you put the steps in the issue summary? Also, yes, it is definitely a real problem.

gceja’s picture

Issue summary: View changes
cilefen’s picture

Thank you!

cilefen’s picture

Status: Active » Needs review
FileSize
804 bytes
dawehner’s picture

Issue tags: +Needs tests

We ideally would have tests ...

cilefen’s picture

Something like this, but not exactly like this, should work.

dawehner’s picture

+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
@@ -259,6 +259,26 @@ public function testRenderTrimmedWithMoreLink() {
+    $this->assertEquals($expected_result, $result);

We could also check that the result is a ViewsRenderPipeLineMarkup object ...

Status: Needs review » Needs work

The last submitted patch, 14: views_no_results-2610236-14.patch, failed testing.

aerozeppelin’s picture

Status: Needs work » Needs review
FileSize
1.92 KB
1.09 KB

Tests as per #14 and #15.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Thank you @aerozeppelin for the assertion.

The last submitted patch, 14: views_no_results-2610236-14.patch, failed testing.

dawehner’s picture

+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
@@ -264,18 +264,15 @@ public function testRenderTrimmedWithMoreLink() {
+    $this->assertInstanceOf('\Drupal\views\Render\ViewsRenderPipelineMarkup', $result);

Just a future tip: You can use ViewsRenderPipelinkeMarkup::class to get the full classname here, pretty handy in some places

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed 1f504dd on 8.1.x
    Issue #2610236 by cilefen, aerozeppelin: Views - "No Results Behavior"...

  • catch committed a7fa07d on
    Issue #2610236 by cilefen, aerozeppelin: Views - "No Results Behavior"...

Status: Fixed » Closed (fixed)

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

Joefry’s picture

Version: 8.0.x-dev » 8.0.3
Priority: Major » Normal
Status: Closed (fixed) » Needs work

I'm using 8.0.3 and the module has the changes in patch 2610236-17.patch included.

but i still get this result:

entered in "no results": <h2>{{ field_vegetable }}</h2><span> some text</span>

view shows: <h2>Rutabaga</h2><span> some text</span>
(escapes html)

cilefen’s picture

Version: 8.0.3 » 8.1.x-dev
Priority: Normal » Major

Just some housekeeping: This was Major priority. It still is Major if not fixed. Branch 8.0.x is closed for changes. It would be good to see if this is reproducible on 8.1.0-rc1.
Since this is fixed, and has tests, I am not sure what is going on here.

Lendude’s picture

Status: Needs work » Closed (fixed)

I can't reproduce the issue on the current HEAD. HTML (with tokens) works when set in 'No results text'. If you still have this issue, please give some detailed steps to reproduce.

frazac’s picture

Drupal 8.1.3, but this patch isn't still included?

<div class="noimage">&nbsp;</div>

give

&lt;div class=&quot;noimage&quot;&gt;&amp;nbsp;&lt;/div&gt;

Tell me if you need more details

Thanks!

Leksat’s picture

Status: Closed (fixed) » Active

I have found a way to reproduce the bug on the latest 8.2.x. The "No results text" is escaped when the "Hide rewriting if empty" checkbox is unchecked.

Leksat’s picture

Views render logic is pretty complicated, but I think I found the bug reason.

Here is the value-is-safe check:

$value_is_safe = $this->last_render instanceof MarkupInterface;

But the MarkupTrait::create() always returns empty string if an empty string was passed in.

Status: Needs review » Needs work

The last submitted patch, 30: 2610236-30--test-only.patch, failed testing.

Leksat’s picture

Status: Needs work » Needs review

Patch works.

dawehner’s picture

Thank you for your patch!

Do you mind changing this small bit?

+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
@@ -264,15 +264,20 @@ public function testRenderTrimmedWithMoreLink() {
   public function testRenderNoResult() {
-    $this->setupDisplayWithEmptyArgumentsAndFields();
-    $field = $this->setupTestField(['empty' => 'This <strong>should work</strong>.']);
-    $field->field_alias = 'key';
-    $row = new ResultRow(['key' => '']);
+    foreach ([TRUE, FALSE] as $hide_alter_empty) {
+      $this->setupDisplayWithEmptyArgumentsAndFields();
+      $field = $this->setupTestField([
+        'empty' => 'This <strong>should work</strong>.',
+        'hide_alter_empty' => $hide_alter_empty,
+      ]);
+      $field->field_alias = 'key';
+      $row = new ResultRow(['key' => '']);
 
-    $expected_result = 'This <strong>should work</strong>.';
-    $result = $field->advancedRender($row);
-    $this->assertEquals($expected_result, $result);
-    $this->assertInstanceOf('\Drupal\views\Render\ViewsRenderPipelineMarkup', $result);
+      $expected_result = 'This <strong>should work</strong>.';
+      $result = $field->advancedRender($row);
+      $this->assertEquals($expected_result, $result);
+      $this->assertInstanceOf('\Drupal\views\Render\ViewsRenderPipelineMarkup', $result);
+    }
   }

foreach in tests should be always replaced by a @dataProvider

Leksat’s picture

Sorry, somehow I never heard of @dataProvider :D Cool stuff actually!

The last submitted patch, 34: 2610236-34--test-only.patch, failed testing.

Lendude’s picture

Test and fix look good.

+++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
@@ -1214,7 +1214,7 @@ public function renderText($alter) {
+    $value_is_safe = $this->last_render instanceof MarkupInterface || (string) $this->last_render === '';
     // Cast to a string so that empty checks and string functions work as
     // expected.
     $value = (string) $this->last_render;

Feels weird to cast it to a string twice in two consecutive lines but can't really think of a way to handle this logic with doing it just once.

Issue summary could really use an update to reflect the problem that still exists after the committed fix in #21.

  • catch committed 1f504dd on 8.3.x
    Issue #2610236 by cilefen, aerozeppelin: Views - "No Results Behavior"...

  • catch committed 1f504dd on 8.3.x
    Issue #2610236 by cilefen, aerozeppelin: Views - "No Results Behavior"...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cilefen’s picture

Status: Needs review » Fixed

@timplunkett, @alexpott, @dawehner, @xjm and I discussed this in a triage session at DrupalCon Dublin. We feel the special case is no longer major. Please open a normal priority follow-up issue for the improvement in #34.

Status: Fixed » Closed (fixed)

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