[gnome-shell] messageTray: improve bad-markup handling



commit 7542e68b6fca5ad02459576b350149c97743675b
Author: Dan Winship <danw gnome org>
Date:   Wed May 4 11:15:45 2011 -0400

    messageTray: improve bad-markup handling
    
    _fixMarkup() was supposed to be ensuring that the markup we passed to
    clutter was correct, but it was validating the syntax incorrectly, and
    wasn't checking that the markup was valid (or even well-formed). This
    is bad because if you pass bad pango markup to
    clutter_text_set_markup(), it will g_warn and drop the string on the
    floor.
    
    Fix by fixing up the regexps, and then calling Pango.parse_markup() on
    the result, and just xml-escaping everything if parse_markup() fails.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=650298

 js/ui/messageTray.js |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 41475c1..4dc949e 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -68,14 +68,19 @@ function _fixMarkup(text, allowMarkup) {
         // Support &amp;, &quot;, &apos;, &lt; and &gt;, escape all other
         // occurrences of '&'.
         let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&amp;');
+
         // Support <b>, <i>, and <u>, escape anything else
         // so it displays as raw markup.
-        return _text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, '&lt;$1');
-    } else {
-        // Escape everything
-        let _text = text.replace(/&/g, '&amp;');
-        return _text.replace(/</g, '&lt;');
+        _text = _text.replace(/<(?!\/?[biu]>)/g, '&lt;');
+
+        try {
+            Pango.parse_markup(_text, -1, '');
+            return _text;
+        } catch (e) {}
     }
+
+    // !allowMarkup, or invalid markup
+    return GLib.markup_escape_text(text, -1);
 }
 
 function URLHighlighter(text, lineWrap, allowMarkup) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]