Problem/Motivation
If you have text in a node body with HTML entities in it, and search for "&", your search result will have garbled things in it like <strong>&</strong>amp;.
The reason is that:
a) When you search for "&", Drupal is actually searching for "& amp;" (without the space) in the indexed content, so it is more than 3 characters and is treated as an actual keyword. (Search terms with fewer than 3 characters are normally ignored).
b) When the excerpt is generated, it is now looking for matches for just & and for some reason it thinks it is OK to break up an entity into pieces and wrap part of it in a STRONG tag. This is the bug.
To reproduce, put the following in the HTML source of a node body, run Cron to index, and search for "&":
Dignissim Aliquam & Quieligo meus natu quae quia te. Damnum© erat— neo pneum. Facilisi feugiat ibidem ratis.
Proposed resolution
Fix the search highlighting so that it doesn't break up HTML entities.
Note: Between when this issue was reported and now, this issue was apparently fixed in Drupal 8 along with some other fixes to the search excerpt production process. So the Drupal 8 patch is just a regression test to ensure it doesn't break again. For Drupal 7, we'll actually have to fix the issue, or more probably if/when the other issue where this was actually fixed gets backported to D7, this issue will go away there too and we can just backport the test.
Beta phase evaluation
| Issue category | Bug because search excerpt highlighting should not break up entities. |
|---|---|
| Prioritized changes | This is a site visitor-facing UI bug fix, so it is prioritized. Actually in Drupal 8 the bug was fixed elsewhere, so it's only a test being added now. |
| Disruption | No API changes. Not disruptive. |
Remaining tasks
Make a patch with a test. [just a test in Drupal 8, the bug got fixed elsewhere]
User interface changes
HTML entities will not be broken up by STRONG tags in search excerpt highlighting.
API changes
None.
Original report by @mygumbo
When the search terms include an &, e.g. language & literature, search results display HTML entities that have not been decoded such as
Saigyo's Poems "Upon Seeing
where the ampersand chat in the HTML entity is wrapped in a strong tag:
Saigyo
<strong>&</strong>
#039;s Poems
<strong>&</strong>
quot;Upon Seeing
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | 2060553-20.patch | 1.61 KB | sivaji_ganesh_jojodae |
| #8 | 2060553-test.patch | 1.92 KB | jhodgdon |
| #2 | entities.png | 4.36 KB | jhodgdon |
Comments
Comment #1
jhodgdonReally? I thought keywords had to be at least 3 characters to be considered anyway, and that punctuation was filtered out... We'll have to look into this...
Comment #2
jhodgdonI just tested this in Drupal 8. If I make a page with an HTML entity in the body, and verify that the entity does not display on the page itself, then search is also not displaying the entity. So this is not a bug in 8.x.
I also tested in Drupal 7.23. It is not a bug there either.
My guess is that your content does not really have an entity in it?
I also tested with your suggested content -- note that two & were missing from your original -- here is the corrected HTML source:
which renders as
Saigyo
&
's Poems
&
"Upon Seeing
This worked fine too (see screenshot).
Comment #3
jhodgdonsorry, wrong version/status
Comment #4
manningpete commentedI am able to recreate this bug both in standard installs of D7 and D8 using these steps:
I think this may be related to how the search string renders the ampersand in the URL.
Comment #5
jhodgdonHm. I tried this in Drupal 8... With the suggested text, even with the CKEditor module uninstalled and Full HTML text format, your text didn't work in the node body -- some of the entities didn't turn into characters at rendering. But I was able to get this text to work:
So I made a node with that in it, and ran cron. With that text, I was able to reproduce your result: if you put & in the keywords when you search, you'll get something like
in the output.
I think there are two things going on:
a) When you search for "&", Drupal is actually searching for "& amp;" (without the space) in the indexed content, so it is more than 3 characters and is treated as an actual keyword.
b) When the excerpt is generated, it is now looking for just & and for some reason it thinks it is OK to break up an entity into pieces and wrap part of it in a STRONG tag.
So, thanks! This does seem to be a real bug and we should fix it.
Comment #6
jhodgdonThis was on the wrong version.
Comment #7
jhodgdonAdded summary.
Comment #8
jhodgdonWell, something changed in the last 3 months -- we've been working on some things in Search lately. I am unable to reproduce this issue in Drupal 8 now, and the test I wrote for it passed too. Now if you search for "&", you get the "You must include at least one positive keyword" message, which is appropriate. I even checked it with the search keywords minimum length set to 1 and got the same message -- I think & is punctuation, which I also think is appropriate.
So how about if we commit this small test change for 8, to make sure this stays fixed, and then move this issue to 7 for possible bug fixing (although without an active D7 search module maintainer, fixing it there is unlikely... maybe the Drupal 8 fix that fixed this will get into 7, but that is also unlikely).
Comment #10
pwolanin commentedI will review
Comment #11
jhodgdonStill applies and test still passes, and this is just a test added so it should be a quick review (hint hint!)
Comment #13
pwolanin commentedregression test looks useful for 8, and opens the door to fix 7
Comment #14
jhodgdonUpdating summary so committers do not get confused about D8 status.
Comment #17
jhodgdonWeird, totally unrelated failure in Drupal\views\Tests\Plugin\RowRenderCacheTest.
Comment #18
alexpottCommitted 9ac248b and pushed to 8.0.x. Thanks!
Thanks for adding the beta to the issue summary.
Comment #20
sivaji_ganesh_jojodae commentedPatch attached for Drupal 7.
Comment #21
jhodgdonInteresting. I just tested on simplytest.me and the bug has indeed also vanished in D7. So let's just go ahead and commit the D7 test, which looks like a good backport. Thanks very much for the patch!
Comment #22
David_Rothstein commentedCommitted to 7.x - thanks!