History

avcodec/ass,webvttdec: fix handling of backslashes

Backslashes cannot be escaped by a backslash in any ASS renderer, but unless followed by specific characters it is just printed out. Insert a word-joiner character after a backslash to break up active sequences without changing the visual output.

Oneric committed 2 years ago

Commit baa64fa1 parent 7b8b4cd2 files · +9 −2Browse files

Unified · Split

2 files
  1. libavcodec/ass.c +8 −1
  2. libavcodec/webvttdec.c +1 −1
libavcodec/ass.c+8−1
@@ -183,9 +183,16 @@ void ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size, · 182 unmodified lines
183 183
184 /* standard ASS escaping so random characters don't get mis-interpreted184 /* standard ASS escaping so random characters don't get mis-interpreted
185 * as ASS */185 * as ASS */
186 } else if (!keep_ass_markup && strchr("{}\\", *p)) {186 } else if (!keep_ass_markup && strchr("{}", *p)) {
187 av_bprintf(buf, "\\%c", *p);187 av_bprintf(buf, "\\%c", *p);
188 188
189 /* append word-joiner U+2060 as UTF-8 to break up sequences like \N */
190 } else if (!keep_ass_markup && *p == '\\') {
191 if (p_end - p <= 3 || strncmp(p + 1, "\xe2\x81\xa0", 3))
192 av_bprintf(buf, "\\\xe2\x81\xa0");
193 else
194 av_bprintf(buf, "\\");
195
189 /* some packets might end abruptly (no \0 at the end, like for example196 /* some packets might end abruptly (no \0 at the end, like for example
190 * in some cases of demuxing from a classic video container), some197 * in some cases of demuxing from a classic video container), some
191 * might be terminated with \n or \r\n which we have to remove (for198 * might be terminated with \n or \r\n which we have to remove (for
libavcodec/webvttdec.c+1−1
@@ -37,7 +37,7 @@ static const struct { · 36 unmodified lines
37 {"<i>", "{\\i1}"}, {"</i>", "{\\i0}"},37 {"<i>", "{\\i1}"}, {"</i>", "{\\i0}"},
38 {"<b>", "{\\b1}"}, {"</b>", "{\\b0}"},38 {"<b>", "{\\b1}"}, {"</b>", "{\\b0}"},
39 {"<u>", "{\\u1}"}, {"</u>", "{\\u0}"},39 {"<u>", "{\\u1}"}, {"</u>", "{\\u0}"},
40 {"{", "\\{"}, {"}", "\\}"}, // escape to avoid ASS markup conflicts40 {"{", "\\{"}, {"}", "\\}"}, {"\\", "\\\xe2\x81\xa0"}, // escape to avoid ASS markup conflicts
41 {"&gt;", ">"}, {"&lt;", "<"},41 {"&gt;", ">"}, {"&lt;", "<"},
42 {"&lrm;", "\xe2\x80\x8e"}, {"&rlm;", "\xe2\x80\x8f"},42 {"&lrm;", "\xe2\x80\x8e"}, {"&rlm;", "\xe2\x80\x8f"},
43 {"&amp;", "&"}, {"&nbsp;", "\\h"},43 {"&amp;", "&"}, {"&nbsp;", "\\h"},

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t