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:

| Comment | File | Size | Author |
|---|---|---|---|
| #54 | 2714131.patch | 5.58 KB | korn3000 |
| #52 | 2714131-52.patch | 5.56 KB | akram khan |
| #51 | 2022-11-17_00-05.png | 88.4 KB | stpaultim |
| #47 | 2714131-47.patch | 5.58 KB | vladimiraus |
| #34 | 2714131-34.patch | 635 bytes | jibran |
Comments
Comment #2
dawehnerI would argue that this is sort of major, as for example there is a workaround of just uninstalling the quickedit module
Comment #3
Anonymous (not verified) commentedLooking 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.
Comment #4
Anonymous (not verified) commentedComment #5
Anonymous (not verified) commentedAlso, 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.
Comment #6
cilefen commentedCan you not use them "Correct faulty" and trim at the same time successfully?
Comment #7
Anonymous (not verified) commentedThe 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.
Comment #8
cilefen commentedIt 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".
Comment #9
Anonymous (not verified) commented??? 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.
Comment #10
Anonymous (not verified) commentedComment #11
cilefen commentedWhat would you have Drupal do to fix this?
Comment #12
Anonymous (not verified) commentedThe proposed patch fixes the issue... so that. If you have a trim display formatter it should correct the HTML of the display regardless.
Comment #13
cilefen commentedSorry for the grumpiness, not having a great day here—that's not your fault.
So this is effectively checking the box for them?
Comment #14
Anonymous (not verified) commented:) 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.
Comment #15
cilefen commented8.0.x is closed for development.
Comment #23
pameeela commentedI'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.
Comment #24
jibranLet's add some tests.
The code comment can't be > 80 chars.
Comment #25
pameeela commentedUpdated patch attached with a shorter comment.
Comment #26
ramya balasubramanian commentedComment #27
jibranTurns out we already have tests for this and they are failing. With the fix this time.
Comment #28
pameeela commentedNot ready for review since it needs tests and now we're debating whether it's even a bug - since the patch breaks existing tests.
Comment #29
pameeela commentedOK jibran's patch may fix the tests so this is ready for review, if it passes.
Comment #32
jibranThere was random fail in first run which is gone after another test run. Now patch is ready for a review.
Comment #33
quietone commentedSo, the test TextSummaryTest.php was passing but was testing the wrong strings and it now updated to test for the correct HTML.
Why is the faulty HTML only fixed when there is s format?
There are also coding standard errors.
Comment #34
jibranThe more I think about it the more it feels like a 'work as designed' to me. Here is why:
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 havefilter_htmlcorrectorin the first place. This is the only use offilter_htmlcorrectorhere.I think this is a support request and OP needs to enable
filter_htmlcorrectorfilter to fix the problem.Anyway, here the fix only patch without tests for anyone who needs that. Please don't test it.
Comment #35
pameeela commentedWhy 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?
Comment #36
jibranThe '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 whenfilter_htmlcorrectoris part of the format.Here are three cases:
filter_htmlcorrectoris not set.filter_htmlcorrectoris set.Comment #37
pameeela commentedErr - 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:

Comment #38
jibranLOL, @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.Comment #39
pameeela commentedI 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 :)
Comment #40
vladimirausThanks for the commit.
Works on
8.9.2,9.0.3and9.1.x.Seems like it was working for most of the tags but
strongComment #41
larowlanWe don't seem to have any new test coverage here?
ie. if this resolves a bug, why isn't an existing test failing?
Comment #44
quietone commentedStill needs a test.
Comment #45
mohit_aghera commentedWhile 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.
Comment #47
vladimirausThe logic has changed in 9.3. Updated patch.
Comment #51
stpaultim commentedThis 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.
Comment #52
akram khanreroll Patch for 10.1.x
Comment #54
korn3000 commentedreroll Patch for 10.2.x
Comment #55
luke.stewart commentedJust noting here to help future me (and others) that looks like the following awesomeness can occur - that sent me deep into the weeds.
If you are displaying a content type using a display mode that uses a trimmed text field it can truncate html in a way that there is an open tag. In my case this was a
<b>because the closing tag was after the full stop.This then caused a host of drupalSettings. to be undefined, and while drupalSettings existed - it was empty. so for example drupalSettings.user was undefined causing various errors in contextual links. (adding to help search indexing).
https://drupal.stackexchange.com/questions/270863/drupalsettings-object-...
Which when I inspected source to see if I was experiencing the same - identified that there was some invalid html.
While I manually corrected the broken HTML I figured it wasn't great you could break the site by accidentally highlighting the space after the fullstop to close your bold text... Which lead me here.
I applied the patch and it applied cleanly on 10.3.6 with some offsets.
In my use case I had a View outputting nodes using a summary display mode. Before and After applying the patch I still see the broken html. I'm not clear from the above if this is supposed to fix this case or not. However updating text modes to select fix faulty and broken html resolved the above.
Comment #57
smustgrave commentedTriaging my component queues.
I tried following the steps in the summary on main branch but not getting any errors. Can anyone confirm still an issue?
If no follow up could be closed in 3 months.
Comment #58
smustgrave commentedSince there's been no follow up going to close out. If still an issue please re-open.