Hi,

I am getting the lots of jquery error, So It would break all the jquery functionality in that page.

Steps to reproduce the issue :

1. Set Body field format as Trimmed with limit (100 char) in Teaser mode
2. Create article node with tag in body field
for example :
<p><em>Globally myocardinate orthogonal communities through frictionless leadership skills. Completely engage client-based customer service and cross-platform human capital. Professionally generate vertical web-readiness rather than magnetic data. Distinctively target optimal infomediaries via synergistic products. Interactively develop vertical manufactured products and highly efficient niche markets.</em></p>
Add these in the body field. and save the node.
3. Then see the article node in teaser mode, you would see the jquery errors.

Before patch - italics apply to the rest of the page:

After patch - italics are correctly clipped at the end of the summary:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

leopathu created an issue. See original summary.

dawehner’s picture

Priority: Critical » Major

I would argue that this is sort of major, as for example there is a workaround of just uninstalling the quickedit module

Anonymous’s picture

FileSize
637 bytes

Looking at this bug, if you enable "Correct faulty and chopped off HTML" on admin/config/content/formats/manage/basic_html (or whatever text format you're using) this problem is fixed.

However, I think the HTML should be corrected on trimmed text no matter what, the errors shouldn't ever happen in the first place. Here's a patch to text.module when trimming that fixes the problem.

Anonymous’s picture

Status: Active » Needs review
Anonymous’s picture

Also, to clarify the bug is when trimming the text to 100 characters. the p and em tags are not ended properly and you have faulty HTML in the body field.

cilefen’s picture

Status: Needs review » Active

Can you not use them "Correct faulty" and trim at the same time successfully?

Anonymous’s picture

The point of the solution is that the "trim" display formatter cannot be used reliably without also using the "correct faulty HTML" setting, and you should be able to IMO.

cilefen’s picture

Status: Active » Closed (works as designed)

It seems for sure there would be no other way. Drupal can trim text, but if that leaves tags hanging open, it is the site builder's responsibility to check the box "correct faulty HTML".

Anonymous’s picture

??? so conflicts with the quickedit module are acceptable if the site builder is magically expected to know that "correct faulty HTML" option exists when configuring their field display? I think closing this is a bit bold and this is a site builder UX fail.

Anonymous’s picture

Status: Closed (works as designed) » Active
cilefen’s picture

What would you have Drupal do to fix this?

Anonymous’s picture

The proposed patch fixes the issue... so that. If you have a trim display formatter it should correct the HTML of the display regardless.

cilefen’s picture

Component: quickedit.module » text.module
Status: Active » Needs review

Sorry for the grumpiness, not having a great day here—that's not your fault.

So this is effectively checking the box for them?

Anonymous’s picture

:) no problem. It does effectively do the "correct faulty HTML" in the event of a trim display formatter. An assumption on Drupal's part, maybe, but probably a good one in most cases since otherwise it requires someone to actually know the "correct faulty HTML" option exists. Maybe others can weigh in whether or not it should do that.

I can see a use case where one display mode uses "trim" while another uses default that doesn't want the correct faulty HTML option checked in the text format. In that case, "trim" should still work and not cause JS conflicts due to incomplete HTML tags.

cilefen’s picture

Title: Getting jquery error (Toolbar and contextual link not working) » Trimmed body display format can result in faulty and chopped off HTML if "Correct faulty and chopped off HTML" is not activated on the text format
Version: 8.0.x-dev » 8.1.x-dev

8.0.x is closed for development.

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.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

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

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

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

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

pameeela’s picture

Version: 8.9.x-dev » 9.0.x-dev
Priority: Major » Normal
Issue summary: View changes
Issue tags: +Bug Smash Initiative
FileSize
129.24 KB
119.72 KB

I've confirmed this is still occurring, but I don't think it meets the criteria for Major since there is a very easy workaround of enabling "Correct faulty and chopped off HTML".

Incredibly, the patch still applies, and it works as advertised. Updated IS with screenshots of before and after. Leaving in review as this seems simple enough but the patch still needs a code review.

jibran’s picture

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

Let's add some tests.

+++ b/core/modules/text/text.module
@@ -150,8 +150,8 @@ function text_summary($text, $format = NULL, $size = NULL) {
+  // Even if the htmlcorrector filter is not present, fix the trimmed summary's faulty HTML.

The code comment can't be > 80 chars.

pameeela’s picture

Updated patch attached with a shorter comment.

Ramya Balasubramanian’s picture

Status: Needs work » Needs review
jibran’s picture

Version: 9.0.x-dev » 9.1.x-dev
Issue tags: -Needs tests
FileSize
2.07 KB
2.65 KB

Turns out we already have tests for this and they are failing. With the fix this time.

pameeela’s picture

Status: Needs review » Needs work

Not ready for review since it needs tests and now we're debating whether it's even a bug - since the patch breaks existing tests.

pameeela’s picture

Status: Needs work » Needs review

OK jibran's patch may fix the tests so this is ready for review, if it passes.

The last submitted patch, 25: 2714131-25.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 27: 2714131-27.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jibran’s picture

Status: Needs work » Needs review

There was random fail in first run which is gone after another test run. Now patch is ready for a review.

quietone’s picture

Status: Needs review » Needs work

So, the test TextSummaryTest.php was passing but was testing the wrong strings and it now updated to test for the correct HTML.

+++ b/core/modules/text/text.module
@@ -152,8 +152,8 @@ function text_summary($text, $format = NULL, $size = NULL) {
+  // Fix faulty HTML in the trimmed summary.

Why is the faulty HTML only fixed when there is s format?

There are also coding standard errors.

jibran’s picture

Status: Needs work » Needs review
FileSize
635 bytes

The more I think about it the more it feels like a 'work as designed' to me. Here is why:

Why is the faulty HTML only fixed when there is s format?

If the answer to this question is, yes, we should fix that too then that would mean \text_summary() will fix all the faulty chopped trims so why even have filter_htmlcorrector in the first place. This is the only use of filter_htmlcorrector here.

I think this is a support request and OP needs to enable filter_htmlcorrector filter to fix the problem.

Anyway, here the fix only patch without tests for anyone who needs that. Please don't test it.

pameeela’s picture

Why is the faulty HTML only fixed when there is s format?

The 'Trimmed' formatter is only available for formatted text fields, so this only applies when there is a format. Unless I am misunderstanding the question?

jibran’s picture

The 'Trimmed' formatter is only available for formatted text fields, so this only applies when there is a format. This statement is incorrect. Trimmed is not a format. Trimmed is just for summary fields, in the context of this issue. A summary field has the same filter as its corresponding textarea. A summary field get trimmed either by <!--break--> string, text.settings.default_summary_length, or the size provided to \text_summary(). The trimmed output is only corrected when filter_htmlcorrector is part of the format.

Here are three cases:

  1. HTML will not be corrected if there is no filter format.
  2. HTML will not be corrected if there is a filter fomrat and filter_htmlcorrector is not set.
  3. HTML will corrected if there is a filter and filter_htmlcorrector is set.
pameeela’s picture

Trimmed is not a format.

Err - yes it is? And this issue occurs when using it, regardless of whether there is a summary involved. And it is not applicable to plain text fields.

This is a screenshot of the display settings for a Text (formatted, long, with summary) field:

This is a screenshot of the display settings for a Text (formatted, long) field:

This is a screenshot of the display settings for a Text (plain, long) field:

jibran’s picture

Issue summary: View changes
FileSize
17.67 KB

LOL, @quietone and I are talking about filter format or text format in the UI and you are talking about field formatter and formatted fields which are textfield, textarea, and textarea with summary with filter format.

These are filter formats:

It is true that from the UI you can't set format to NULL but \text_summary() can work with NULL format hence @quietone's question.

pameeela’s picture

I know that you were talking about text formats, that is why I said it's not possible to use the trimmed formatter on a field that doesn't have a text format :)

VladimirAus’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the commit.
Works on 8.9.2, 9.0.3 and 9.1.x.
Seems like it was working for most of the tags but strong

larowlan’s picture

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

We don't seem to have any new test coverage here?

ie. if this resolves a bug, why isn't an existing test failing?

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs review » Needs work

Still needs a test.

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
5.81 KB
5.19 KB

While attempting to write the test cases for the issue, I noticed a few things:
- To resolve current failures, I had to fix multiple test cases so it passes existing tests. Mainly those are related to expected strings only.
Is it the right approach? I am not sure if there can be additional regressions.
I need some inputs from someone.

- I added a test case to validate the string normalization. Is it sufficient or we need to render and check string over there as well?

Keeping "Needs tests" tag as it is until we have conclusion on above points.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

VladimirAus’s picture

FileSize
5.58 KB

The logic has changed in 9.3. Updated patch.

Status: Needs review » Needs work

The last submitted patch, 47: 2714131-47.patch, failed testing. View results

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

stpaultim’s picture

FileSize
88.4 KB

This might be a slightly different issue, but I want to post this because it might help folks with a problem that looks a LOT like this problem if you are trimming content in a views rewrite field.

Check the "Field can contain HTML" option to fix it.

A screenshot of the views rewrite field

Akram Khan’s picture

reroll Patch for 10.1.x

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.