Do all text -> HTML conversion for subtitles in the same place.
authorCarl Hetherington <cth@carlh.net>
Sun, 1 Aug 2021 00:02:28 +0000 (02:02 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 1 Aug 2021 00:02:28 +0000 (02:02 +0200)
Previously we would convert > to &gt; then the ampersand to &amp;
resulting in &amp;gt;

src/lib/render_text.cc
src/lib/text_decoder.cc

index e47098ee906916da55ce02ba71686a6c486726d0..7bb7d6b456990d2b12f21f1a4ec343d8534290d2 100644 (file)
@@ -77,11 +77,7 @@ marked_up (list<StringText> subtitles, int target_height, float fade_factor)
                /* Between 1-65535 inclusive, apparently... */
                out += "alpha=\"" + dcp::raw_convert<string>(int(floor(fade_factor * 65534)) + 1) + "\" ";
                out += "color=\"#" + i.colour().to_rgb_string() + "\">";
-
-               string t = i.text();
-               replace_all(t, "&", "&amp;");
-               out += t;
-
+               out += i.text();
                out += "</span>";
        }
 
index 0a7bdf95da75ffc32f428d095929d8b891bb4b0d..6ee6ed079879e014c33df5c2c4bc36e79b336881 100644 (file)
@@ -72,10 +72,11 @@ void
 TextDecoder::emit_plain_start (ContentTime from, list<dcp::SubtitleString> s)
 {
        for (auto& i: s) {
-               /* We must escape < and > in strings, otherwise they might confuse our subtitle
-                  renderer (which uses some HTML-esque markup to do bold/italic etc.)
+               /* We must escape some things, otherwise they might confuse our subtitle
+                  renderer (which uses entities and some HTML-esque markup to do bold/italic etc.)
                */
                string t = i.text ();
+               boost::algorithm::replace_all (t, "&", "&amp;");
                boost::algorithm::replace_all (t, "<", "&lt;");
                boost::algorithm::replace_all (t, ">", "&gt;");
                i.set_text (t);