Bug 1301186 - Invitation preview may get broken if non ascii characters occur;r=philipp;a=philipp
authormakemyday@gmx-topmail.de
Fri, 14 Oct 2016 00:53:58 +0200
changeset 25687 47c2e4ec12d375d48740922b00368c8c48eb4124
parent 25686 c9c6ad534cd096cd2e9352c5fb335b002b0a4922
child 25688 7b9e92b32ac49bdf34135d9078e200124cfe68f0
push id1742
push usermakemyday@gmx-topmail.de
push dateSat, 15 Oct 2016 16:30:26 +0000
treeherdercomm-beta@47c2e4ec12d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp, philipp
bugs1301186
Bug 1301186 - Invitation preview may get broken if non ascii characters occur;r=philipp;a=philipp
calendar/lightning/modules/ltnInvitationUtils.jsm
calendar/test/unit/test_ltninvitationutils.js
--- a/calendar/lightning/modules/ltnInvitationUtils.jsm
+++ b/calendar/lightning/modules/ltnInvitationUtils.jsm
@@ -89,20 +89,27 @@ ltn.invitation = {
 
             if (aContentText) {
                 let content = doc.getElementById("imipHtml-" + aField + "-content");
                 doc.getElementById("imipHtml-" + aField + "-row").hidden = false;
                 if (aConvert) {
                     // we convert special characters first to not mix up html conversion
                     let mode = Components.interfaces.mozITXTToHTMLConv.kEntities;
                     let contentText = linkConverter.scanTXT(aContentText, mode);
-                    mode = Components.interfaces.mozITXTToHTMLConv.kStructPhrase +
-                           Components.interfaces.mozITXTToHTMLConv.kGlyphSubstitution +
-                           Components.interfaces.mozITXTToHTMLConv.kURLs;
-                    content.innerHTML = linkConverter.scanHTML(contentText, mode);
+                    try {
+                        // kGlyphSubstitution may lead to unexpected results when used in scanHTML
+                        mode = Components.interfaces.mozITXTToHTMLConv.kStructPhrase +
+                               Components.interfaces.mozITXTToHTMLConv.kGlyphSubstitution +
+                               Components.interfaces.mozITXTToHTMLConv.kURLs;
+                        content.innerHTML = linkConverter.scanHTML(contentText, mode);
+                    } catch (e) {
+                        mode = Components.interfaces.mozITXTToHTMLConv.kStructPhrase +
+                               Components.interfaces.mozITXTToHTMLConv.kURLs;
+                        content.innerHTML = linkConverter.scanHTML(contentText, mode);
+                    }
                 } else {
                     content.textContent = aContentText;
                 }
             }
         }
 
         // Simple fields
         let headerDescr = doc.getElementById("imipHtml-header-descr");
--- a/calendar/test/unit/test_ltninvitationutils.js
+++ b/calendar/test/unit/test_ltninvitationutils.js
@@ -141,31 +141,59 @@ add_task(function* createInvitationOverl
     }, {
         input: {
             description: "DESCRIPTION:Or write to mailto:faq@example.net instead.\r\n"},
         expected: {
             node: "imipHtml-description-content",
             value: "Or write to <a xmlns=\"http://www.w3.org/1999/xhtml\" class=\"moz-txt-link-fr" +
                    "eetext\" href=\"mailto:faq@example.net\">mailto:faq@example.net</a> instead."}
     }, {
+        input: { description: "DESCRIPTION:Let's see if +/- still can be displayed.\r\n" },
+        expected: {
+            node: "imipHtml-description-content",
+            value: "Let's see if +/- still can be displayed."
+        }
+    }, {
         input: {
             description: "DESCRIPTION:Or write to faq@example.net instead.\r\n"},
         expected: {
             node: "imipHtml-description-content",
             value: "Or write to <a xmlns=\"http://www.w3.org/1999/xhtml\" class=\"moz-txt-link-ab" +
                    "breviated\" href=\"mailto:faq@example.net\">faq@example.net</a> instead."}
     }, {
         input: {
             description: "DESCRIPTION:It's up to you ;-)\r\n"},
         expected: {
             node: "imipHtml-description-content",
             value: "It's up to you <span xmlns=\"http://www.w3.org/1999/xhtml\" class=\"moz-smile" +
                    "y-s3\" title=\";-)\"><span>;-)</span></span>"}
     }, {
         input: {
+            description: "DESCRIPTION:Let's see how evil we can be: <script language=\"JavaScript" +
+                         "\">document.getElementById(\"imipHtml-description-content\").write(\"Sc" +
+                         "ript embedded!\")</script>\r\n"
+        },
+        expected: {
+            node: "imipHtml-description-content",
+            value: "Let's see how evil we can be: &lt;script language=\"JavaScript\"&gt;document." +
+                   "getElementById(\"imipHtml-description-content\").write(\"Script embedded!\")&" +
+                   "lt;/script&gt;"
+        }
+    }, {
+        input: {
+            description: "DESCRIPTION:Or we can try: <img src=\"document.getElementById(\"imipHtm" +
+                         "l-description-descr\").innerText\" \>\r\n"
+        },
+        expected: {
+            node: "imipHtml-description-content",
+            value: "Or we can try: &lt;img src=\"document.getElementById(\"imipHtml-description-d" +
+                   "escr\").innerText\" \&gt;"
+        }
+    }, {
+        input: {
             url: "URL:http://www.example.org/event.ics\r\n"},
         expected: {
             node: "imipHtml-url-content",
             value: "<a xmlns=\"http://www.w3.org/1999/xhtml\" class=\"moz-txt-link-freetext\" hre" +
                    "f=\"http://www.example.org/event.ics\">http://www.example.org/event.ics</a>"}
     }, {
         input: {
             attach: "ATTACH:http://www.example.org\r\n"},
@@ -383,17 +411,17 @@ add_task(function* compareInvitationOver
                    "<br xmlns=\"\"/>" +
                    "<span xmlns=\"\" class=\"removed\">Wed 9 Sep 2015 1:00 PM – 2:00 PM</span>",
 
                    "<span xmlns=\"\" class=\"added\">Wednesday, September 09, 2015 2:00 PM – 3:00 PM</span>" +
                    "<br xmlns=\"\"/>" +
                    "<span xmlns=\"\" class=\"removed\">Wednesday, September 09, 2015 1:00 PM – 2:00 PM</span>",
 
                    // do not change the patterns above unless there are related test failures when
-                   // running autometed tests
+                   // running automated tests
                    "<span xmlns=\"\" class=\"added\">Wed 09 Sep 2015 2:00 PM – 3:00 PM</span>" +
                    "<br xmlns=\"\"/>" +
                    "<span xmlns=\"\" class=\"removed\">Wed 09 Sep 2015 1:00 PM – 2:00 PM</span>",
 
                    "<span xmlns=\"\" class=\"added\">Wednesday, 09 September, 2015 2:00 PM – 3:00 PM</span>" +
                    "<br xmlns=\"\"/>" +
                    "<span xmlns=\"\" class=\"removed\">Wednesday, 09 September, 2015 1:00 PM – 2:00 PM</span>",