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
183183
184184 /* standard ASS escaping so random characters don't get mis-interpreted
185185 * as ASS */
186− } else if (!keep_ass_markup && strchr("{}\\", *p)) {
186+ } else if (!keep_ass_markup && strchr("{}", *p)) {
187187 av_bprintf(buf, "\\%c", *p);
188188
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+
189196 /* some packets might end abruptly (no \0 at the end, like for example
190197 * in some cases of demuxing from a classic video container), some
191198 * 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
3737 {"<i>", "{\\i1}"}, {"</i>", "{\\i0}"},
3838 {"<b>", "{\\b1}"}, {"</b>", "{\\b0}"},
3939 {"<u>", "{\\u1}"}, {"</u>", "{\\u0}"},
40− {"{", "\\{"}, {"}", "\\}"}, // escape to avoid ASS markup conflicts
40+ {"{", "\\{"}, {"}", "\\}"}, {"\\", "\\\xe2\x81\xa0"}, // escape to avoid ASS markup conflicts
4141 {"&gt;", ">"}, {"&lt;", "<"},
4242 {"&lrm;", "\xe2\x80\x8e"}, {"&rlm;", "\xe2\x80\x8f"},
4343 {"&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