Bug 1663947 - prevent the most common entities from appearing in event/task descriptions. r=darktrojan

This commit is contained in:
Magnus Melin 2021-01-01 12:56:07 +02:00
Родитель a4025cbd42
Коммит 9b21c853ec
2 изменённых файлов: 24 добавлений и 6 удалений

Просмотреть файл

@ -369,18 +369,25 @@ var calview = {
textToHtmlDocumentFragment(text, doc) {
// Convert plain text to HTML. The main motivation here is to convert plain
// text URLs into <a> tags (to linkify them).
let textWithBreaks = text.replace(/\r?\n/g, "<br/>");
let mode, html;
text = text.replace(/\r?\n/g, "<br/>");
// Resolve some of the most common entities.
text = text.replace(/&nbsp;/g, "\u00A0");
text = text.replace(/&copy;/g, "\u00A9");
text = text.replace(/&reg;/g, "\u00AE");
text = text.replace(/&ndash;/g, "\u2013");
text = text.replace(/&mdash;/g, "\u2014");
text = text.replace(/&euro;/g, "\u20AC");
let html;
try {
// kGlyphSubstitution may lead to unexpected results when used in scanHTML.
mode =
let mode =
Ci.mozITXTToHTMLConv.kStructPhrase |
Ci.mozITXTToHTMLConv.kGlyphSubstitution |
Ci.mozITXTToHTMLConv.kURLs;
html = gTextToHtmlConverter.scanHTML(textWithBreaks, mode);
html = gTextToHtmlConverter.scanHTML(text, mode);
} catch (e) {
mode = Ci.mozITXTToHTMLConv.kStructPhrase | Ci.mozITXTToHTMLConv.kURLs;
html = gTextToHtmlConverter.scanHTML(textWithBreaks, mode);
let mode = Ci.mozITXTToHTMLConv.kStructPhrase | Ci.mozITXTToHTMLConv.kURLs;
html = gTextToHtmlConverter.scanHTML(text, mode);
}
// Sanitize and convert the HTML into a document fragment.

Просмотреть файл

@ -262,6 +262,17 @@ add_task(async function createInvitationOverlay_test() {
value: "Or we can try: ",
},
},
{
input: {
description:
'DESCRIPTION:Check <a href="http://example.com">example.com</a>&nbsp;&nbsp;&mdash; only 3 &euro;\r\n',
},
expected: {
node: "imipHtml-description-content",
value:
'Check <a xmlns="http://www.w3.org/1999/xhtml" href="http://example.com">example.com</a>\u00A0\u00A0\u2014 only 3 €',
},
},
{
input: { url: "URL:http://www.example.org/event.ics\r\n" },
expected: {