From 887beb00562a836fb4313aa8d1944587c3a87996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 26 Jun 2017 14:30:30 -0400 Subject: [PATCH 1/2] decode HTML entity numbers corresponding set of supported codes --- src/constants/string_mappings.js | 18 ++++++++++++++++-- test/jasmine/tests/svg_text_utils_test.js | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/constants/string_mappings.js b/src/constants/string_mappings.js index a2760f7b6c0..aff645603da 100644 --- a/src/constants/string_mappings.js +++ b/src/constants/string_mappings.js @@ -10,18 +10,30 @@ 'use strict'; // N.B. HTML entities are listed without the leading '&' and trailing ';' +// https://www.freeformatter.com/html-entities.html module.exports = { - entityToUnicode: { 'mu': 'μ', + '#956': 'μ', + 'amp': '&', + '#28': '&', + 'lt': '<', + '#60': '<', + 'gt': '>', + '#62': '>', + 'nbsp': ' ', + '#160': ' ', + 'times': '×', + '#215': '×', + 'plusmn': '±', - 'deg': '°' + '#177': '±', }, unicodeToEntity: { @@ -33,4 +45,6 @@ module.exports = { '\/': '#x2F' } + 'deg': '°', + '#176': '°' }; diff --git a/test/jasmine/tests/svg_text_utils_test.js b/test/jasmine/tests/svg_text_utils_test.js index 4a118295b80..374d50b9e8e 100644 --- a/test/jasmine/tests/svg_text_utils_test.js +++ b/test/jasmine/tests/svg_text_utils_test.js @@ -262,6 +262,15 @@ describe('svg+text utils', function() { expect(node.text()).toEqual('100μ & < 10 > 0  100 × 20 ± 0.5 °'); }); + it('decodes some HTML entities in text (number case)', function() { + var node = mockTextSVGElement( + '100μ  < 10 > 0  ' + + '100 × 20 ± 0.5 °' + ); + + expect(node.text()).toEqual('100μ & < 10 > 0  100 × 20 ± 0.5 °'); + }); + it('supports superscript by itself', function() { var node = mockTextSVGElement('123'); expect(node.html()).toBe( From 45bd22a9e1c9d0e083363e18454ecac2f1ca0fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Mon, 26 Jun 2017 14:30:49 -0400 Subject: [PATCH 2/2] :hocho: unused unicodeToEntity list --- src/constants/string_mappings.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/constants/string_mappings.js b/src/constants/string_mappings.js index aff645603da..55c4a512317 100644 --- a/src/constants/string_mappings.js +++ b/src/constants/string_mappings.js @@ -34,17 +34,8 @@ module.exports = { 'plusmn': '±', '#177': '±', - }, - - unicodeToEntity: { - '&': 'amp', - '<': 'lt', - '>': 'gt', - '"': 'quot', - '\'': '#x27', - '\/': '#x2F' - } 'deg': '°', '#176': '°' + } };