Problem/Motivation
The suggestion label and descriptions are HTML-escaped in the matcher plugins. This becomes an issue when the values are then used in the user interface other than the LinkIt suggestion list. For example in #2712951: Linkit for Link field the label is injected into the Title for a Link field.
As a result, the URL Title displays escaped html entities:

Steps to reproduce
- Install Drupal Standard and enable LinkIt
- Create a basic page with title "Liberté, Égalité & Fraternité"
- Notice the & is escaped in the autocomplete suggestion at /linkit/autocomplete/default?q=Libert
Proposed resolution
Remove HTML escaping from the matcher plugins. Implement HTML escaping when displaying the suggestions instead.
Remaining tasks
- Write a patch
- Review
- Commit
User interface changes
None.
API changes
None.
Data model changes
Matcher suggestions in the autocomplete json are no longer html escaped.
Original report by idflood
When inserting link in wysiwyg I had an issue with pages having a "&" in title.
To reproduce you can create a page with the title "Bugs & issues" for example, and then on another page you can try to link to it from the wysiwyg:
- When you click on the suggestion the textfield will get "Bugs & issues"
- When you submit and inspect the source of the wysiwyg you will notice that the only has the href attributes (and the href is equal to the title with the &).
The following patch only decode html entities for the entity label and fixes the issue locally.

Issue fork linkit-2981543
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
idflood commentedComment #3
idflood commentedComment #4
idflood commentedThe following patch add a `htmlspecialchars_decode` since there was too an issue with single quote in titles (ex: That's it)
Comment #5
anonWhat version of Linkit are you using?
This is not a default behavior, that's my I'm asking.
I tested with a node named "Tips & Tricks" and it works. The same with "Tips & 'tricks'".
Comment #6
anonComment #7
dddbbb commentedI've also run into this issue but with single quotes as mentioned in #4. The patch in #4 fixes the issue for me. I'm running the current latest dev release of linkit (#1084887).
Comment #8
anonPlease add a test for this.
Comment #9
anonThis does not make any sense to me.
When you select a suggestion in the list, the only thing that will be populated is the "URL field". That field will be populated with the canonical url of the node (node/123).
I do not think you are using Linkit 8.x-5.x.
Comment #10
dddbbb commentedConfirmed. I was using an old dev version (dev-5.x#1084887). Have now updated to 5.0.0-beta9, retested and it seems I no longer need this patch.
Comment #11
zero2one commentedI bumped into the same issue with the latest version of this module (8.x-5.0-beta9).
The patch in comment #4 fixes the issue.
In my case the node I was linking to has "Adoration de l'agneau mystique" as node title.
Comment #12
zero2one commentedComment #13
anonThis is strange as with the default behavior is that the node/nid should be populated when selecting a link from the suggestion list.
Is it a node you are trying to link to?
Comment #14
zero2one commentedYes it is a node.
The problem is that, without the patch, the ′ (not ' ) in the node title is HTML-encoded what results in broken functionality.
Comment #15
anon@zero2one: Sorry but I still don't get it.
From your gifs, I can tell that you are using the wrong version. Are you 100% sure you are using the latest version of 8.x-5.x-dev?
Comment #16
rade commentedI was also dealing with this issue. Patch from #4 fixes it.
Comment #17
anonStill, why does this becomes an issue? I cant reproduce it at all.
See #9
Comment #18
idebr commentedThe suggestion label and descriptions are HTML-escaped in the matcher plugins. This becomes an issue when the values are then used in the user interface other than the LinkIt suggestion list. For example in #2712951: Linkit for Link field the label is injected into the Title for a Link field.
As a result, the URL Title displays escaped html entities:

Attached patch removes HTML escaping from the matcher plugins and implements HTML escaping when displaying the suggestions instead.
Comment #20
anneke_vde commentedAttached patch fixed the error that I got:
Error: Class 'Drupal\linkit\Plugin\Linkit\Matcher\Html' not found in Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher->buildGroup() (regel 480 van /home/anneke/git/nji/htdocs/modules/contrib/linkit/src/Plugin/Linkit/Matcher/EntityMatcher.php)
Comment #21
idebr commented#20 fixes the error, but uses an incorrect approach. Attached patch is based from #18 and updated with the latest changes from HEAD.
Comment #24
ericgsmith commentedI would like to propose an alternative suggestion based on the work in #3355004 which I will close as a duplicate issue.
Rather than removing escaping from the matcher plugin, we can handle the HTML clientside when inserting the value into the title field. This keeps the output from module correctly escaped. I believe it should be the responsibility of the thing using this data to correctly handle the escaped HTML.
No interdiff attached as this is an alternative approach.
Comment #25
ericgsmith commentedComment #27
idebr commentedTypically the output layer does the escaping to prevent duplicate escaping. For reference see #2297711: Fix HTML escaping due to Twig autoescape
Comment #28
idflood commentedI wasn't able to apply patch in #24 to the current 6.0.0 so here is a reroll.
Comment #29
ericgsmith commented#27 - apologies I missed your reply.
RE:
I agree with this - Drupal is still an output layer via the endpoint - and my suggestion is to keep the Drupal application escaping at the output layer.
I believe this is similar to how core handles autocompletes - e.g for a standard entity autocomplete the html is escaped by Drupal so that the JS just renders what it receives https://git.drupalcode.org/project/drupal/-/blob/11.x/core/misc/autocomp...
The difference here is after rendering we are wanting to take something that is HTML back into a plain text context - which I believe we can do by getting the text content of the html element instead of removing any escaping from the backend.
Comment #30
nivethasubramaniyan commentedI applied the patch in drupal 10.1.0 instance with linkit 6.1.0.
After applying the patch, it seems to be working fine . I have attached screenshots for the reference.
Comment #31
mark_fullmerThis rationale makes sense to me, and the resolution is significantly more comprehensible than the approach of removing escaping from the matcher.
I'll proceed to merge this into both the 6.0.x branch (compatible with Drupal 9.x through 10.0.x) and the 6.1.x (compatible with Drupal 10.1.x+).
Comment #34
mark_fullmer