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.
Unified · Split
| @@ -183,9 +183,16 @@ void ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size, · 182 unmodified lines | ||
| 183 | 183 | |
| 184 | 184 | /* standard ASS escaping so random characters don't get mis-interpreted |
| 185 | 185 | * as ASS */ |
| 186 | − } else if (!keep_ass_markup && strchr("{}\\", *p)) { | |
| 186 | + } else if (!keep_ass_markup && strchr("{}", *p)) { | |
| 187 | 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 | 196 | /* some packets might end abruptly (no \0 at the end, like for example |
| 190 | 197 | * in some cases of demuxing from a classic video container), some |
| 191 | 198 | * might be terminated with \n or \r\n which we have to remove (for |
| @@ -37,7 +37,7 @@ static const struct { · 36 unmodified lines | ||
| 37 | 37 | {"<i>", "{\\i1}"}, {"</i>", "{\\i0}"}, |
| 38 | 38 | {"<b>", "{\\b1}"}, {"</b>", "{\\b0}"}, |
| 39 | 39 | {"<u>", "{\\u1}"}, {"</u>", "{\\u0}"}, |
| 40 | − {"{", "\\{"}, {"}", "\\}"}, // escape to avoid ASS markup conflicts | |
| 40 | + {"{", "\\{"}, {"}", "\\}"}, {"\\", "\\\xe2\x81\xa0"}, // escape to avoid ASS markup conflicts | |
| 41 | 41 | {">", ">"}, {"<", "<"}, |
| 42 | 42 | {"‎", "\xe2\x80\x8e"}, {"‏", "\xe2\x80\x8f"}, |
| 43 | 43 | {"&", "&"}, {" ", "\\h"}, |