From f1b4266843aab803e9eb82b3ea35a9a5c479c0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 1 Dec 2017 08:15:57 +0800 Subject: [PATCH] fix(toc): title should escape html entities Fixes #2198, Closes #2437 --- lib/plugins/helper/toc.js | 2 +- test/scripts/helpers/toc.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/plugins/helper/toc.js b/lib/plugins/helper/toc.js index 5f3f7e5f90..ef7d058c7a 100644 --- a/lib/plugins/helper/toc.js +++ b/lib/plugins/helper/toc.js @@ -25,7 +25,7 @@ function tocHelper(str, options) { headings.each(function() { var level = +this.name[1]; var id = $(this).attr('id'); - var text = $(this).text(); + var text = $(this).html(); lastNumber[level - 1]++; diff --git a/test/scripts/helpers/toc.js b/test/scripts/helpers/toc.js index 8b3528ef16..c4e0a84a0e 100644 --- a/test/scripts/helpers/toc.js +++ b/test/scripts/helpers/toc.js @@ -16,7 +16,8 @@ describe('toc', () => { '

Title 1.3

', '

Title 1.3.1

', '

Title 2

', - '

Title 2.1

' + '

Title 2.1

', + '

Title should escape &, <, ', and "

' ].join(''); var genResult = options => { @@ -102,6 +103,12 @@ describe('toc', () => { 'Title 2', '', ifTrue(maxDepth >= 2, resultTitle_2_1, ''), + '', + '
  • ', + '', + ifTrue(listNumber, '3. ', ''), + 'Title should escape &, <, ', and "', + '', '
  • ' ].join('');