Skip to content

Commit 5deb20f

Browse files
gdrapsy-p
authored and
y-p
committed
BUG: fix to_html double escaping
1 parent 71e0f8b commit 5deb20f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pandas/core/format.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas.core.common import adjoin, isnull, notnull
1212
from pandas.core.index import Index, MultiIndex, _ensure_index
1313
from pandas.util import py3compat
14+
from pandas.util.compat import OrderedDict
1415
from pandas.core.config import get_option, set_option, reset_option
1516
import pandas.core.common as com
1617
import pandas.lib as lib
@@ -520,7 +521,10 @@ def _write_cell(self, s, kind='td', indent=0, tags=None):
520521
start_tag = '<%s>' % kind
521522

522523
if self.escape:
523-
esc = {'<' : r'&lt;', '>' : r'&gt;', '&' : r'&amp;'}
524+
# escape & first to prevent double escaping of &
525+
esc = OrderedDict(
526+
[('&', r'&amp;'), ('<', r'&lt;'), ('>', r'&gt;')]
527+
)
524528
else:
525529
esc = {}
526530
rs = com.pprint_thing(s, escape_chars=esc)

0 commit comments

Comments
 (0)