# Highlighting uses DefaultEncoder, leading to incorrect HTML escaping

**URL:** https://discuss.elastic.co/t/highlighting-uses-defaultencoder-leading-to-incorrect-html-escaping/3835
**Category:** Elasticsearch
**Created:** [January 28, 2011, 2:47pm UTC](https://discuss.elastic.co/t/highlighting-uses-defaultencoder-leading-to-incorrect-html-escaping/3835 "2011-01-28T14:47:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Serge\_Nekoval](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Serge\_Nekoval](https://discuss.elastic.co/u/Serge_Nekoval)
#### Post date: [January 28, 2011, 2:47pm UTC](https://discuss.elastic.co/t/highlighting-uses-defaultencoder-leading-to-incorrect-html-escaping/3835/1 "2011-01-28T14:47:15Z")

</div>

I noticed that HighlightPhase.java hardcodes the use of  
DefaultEncoder, which does not escape the text before adding highlight  
tags.  
I know that Lucene supports HTML encoding, so is there a chance to  
support it in ElasticSearch?

The problem is critical for highlighting plain-text fields. If you  
escape a field after highlighting (on client), highlight tags will be  
escaped as well. Note that all user-provided content HAS to be escaped  
if you display it inside HTML page.

Am I the only one experiencing this problem?

---

<div class="post-metadata">

### Author: ![Cory](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@Cory](https://discuss.elastic.co/u/Cory)
#### Post date: [February 24, 2011, 11:55pm UTC](https://discuss.elastic.co/t/highlighting-uses-defaultencoder-leading-to-incorrect-html-escaping/3835/2 "2011-02-24T23:55:03Z")

</div>

This is a problem for me also. Did you find a workaround?

-Cory

On Jan 28, 7:47 am, Serge Nekoval [neko...@gmail.com](mailto:neko...@gmail.com) wrote:

> I noticed that HighlightPhase.java hardcodes the use ofDefaultEncoder, which does not escape the text before adding highlight  
> tags.  
> I know that Lucene supports HTML encoding, so is there a chance to  
> support it in Elasticsearch?
> 
> The problem is critical for highlighting plain-text fields. If you  
> escape a field after highlighting (on client), highlight tags will be  
> escaped as well. Note that all user-provided content HAS to be escaped  
> if you display it inside HTML page.
> 
> Am I the only one experiencing this problem?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 4:11am UTC](https://discuss.elastic.co/t/highlighting-uses-defaultencoder-leading-to-incorrect-html-escaping/3835/3 "2017-07-06T04:11:31Z")

</div>


