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 &amp; Quieligo meus natu quae quia te. Damnum&copy; erat&mdash; 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

Reference: https://www.drupal.org/core/beta-changes
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&#039;s Poems &quot;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

Comments

jhodgdon’s picture

Really? 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...

jhodgdon’s picture

Version: 7.22 » 8.x-dev
Priority: Normal » Major
Status: Active » Closed (cannot reproduce)
StatusFileSize
new4.36 KB

I 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:

 Saigyo
<strong>&</strong>
&#039;s Poems
<strong>&</strong>
&quot;Upon Seeing

which renders as

Saigyo
&
's Poems
&
"Upon Seeing

This worked fine too (see screenshot).

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Priority: Major » Normal

sorry, wrong version/status

manningpete’s picture

Version: 7.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Closed (cannot reproduce) » Active

I am able to recreate this bug both in standard installs of D7 and D8 using these steps:

  1. Using a standard install, create an article or page with the title "Aliquam & Qui"
  2. Add some text to the body containing HTML entities in the first few lines. I added
    Dignissim Aliquam & Quieligo meus &lquot;natu quae quia te&rquot;. Damnum&copy; erat&mdash; neo pneum. Facilisi feugiat ibidem ratis.
  3. Check to make sure there are indeed HTML entities in the source code of the body field (I'm not sure how the above example will render here).
  4. Index your content in search either by running cron or re-indexing at admin/config/search/settings
  5. In search box, enter "Aliquam" and notice search result snippet renders correctly
  6. In search box, enter "Aliquam & Quieligo" (type the ampersand key like a user would; do not use the HTML entity) and notice the search result snippet renders HTML entities
  7. In search box, enter "Aliquam &amp; Quieligo" (type the HTML entity) and notice that the search results render correctly again.

I think this may be related to how the search string renders the ampersand in the URL.

jhodgdon’s picture

Hm. 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:

Dignissim Aliquam &amp; Quieligo meus natu quae quia te. Damnum&copy; erat&mdash; neo pneum. Facilisi feugiat ibidem ratis.

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

<strong>&</strong>amp;

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.

jhodgdon’s picture

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

This was on the wrong version.

jhodgdon’s picture

Issue summary: View changes

Added summary.

jhodgdon’s picture

Status: Active » Needs review
Issue tags: +Needs backport to D7
StatusFileSize
new1.92 KB

Well, 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).

jhodgdon queued 8: 2060553-test.patch for re-testing.

pwolanin’s picture

I will review

jhodgdon’s picture

Still applies and test still passes, and this is just a test added so it should be a quick review (hint hint!)

jhodgdon queued 8: 2060553-test.patch for re-testing.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

regression test looks useful for 8, and opens the door to fix 7

jhodgdon’s picture

Issue summary: View changes

Updating summary so committers do not get confused about D8 status.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 2060553-test.patch, failed testing.

Status: Needs work » Needs review

jhodgdon queued 8: 2060553-test.patch for re-testing.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Weird, totally unrelated failure in Drupal\views\Tests\Plugin\RowRenderCacheTest.

alexpott’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 9ac248b and pushed to 8.0.x. Thanks!

Thanks for adding the beta to the issue summary.

  • alexpott committed 9ac248b on
    Issue #2060553 by jhodgdon, manningpete: Search result snippet displayes...
sivaji_ganesh_jojodae’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.61 KB

Patch attached for Drupal 7.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Interesting. 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!

David_Rothstein’s picture

Title: Search result snippet displayes HTML entities » Test that searching for HTML entities works as expected
Category: Bug report » Task
Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed e67dfa5 on 7.x
    Issue #2060553 by jhodgdon, sivaji@knackforge.com, manningpete: Test...

Status: Fixed » Closed (fixed)

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