mirror of
https://github.com/mpv-player/mpv
synced 2024-08-04 14:59:58 +02:00
common/common.c: handle utf16 in mp_parse_escape
Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
parent
563b4785da
commit
3314483a02
@ -187,9 +187,20 @@ static bool mp_parse_escape(void *talloc_ctx, bstr *dst, bstr *code)
|
|||||||
}
|
}
|
||||||
if (code->start[0] == 'u' && code->len >= 5) {
|
if (code->start[0] == 'u' && code->len >= 5) {
|
||||||
bstr num = bstr_splice(*code, 1, 5);
|
bstr num = bstr_splice(*code, 1, 5);
|
||||||
int c = bstrtoll(num, &num, 16);
|
uint32_t c = bstrtoll(num, &num, 16);
|
||||||
if (num.len)
|
if (num.len)
|
||||||
return false;
|
return false;
|
||||||
|
if (c >= 0xd800 && c <= 0xdbff) {
|
||||||
|
if (code->len < 5 + 6 // udddd + \udddd
|
||||||
|
|| code->start[5] != '\\' || code->start[6] != 'u')
|
||||||
|
return false;
|
||||||
|
*code = bstr_cut(*code, 5 + 1);
|
||||||
|
bstr num2 = bstr_splice(*code, 1, 5);
|
||||||
|
uint32_t c2 = bstrtoll(num2, &num2, 16);
|
||||||
|
if (num2.len || c2 < 0xdc00 || c2 > 0xdfff)
|
||||||
|
return false;
|
||||||
|
c = ((c - 0xd800) << 10) + 0x10000 + (c2 - 0xdc00);
|
||||||
|
}
|
||||||
mp_append_utf8_bstr(talloc_ctx, dst, c);
|
mp_append_utf8_bstr(talloc_ctx, dst, c);
|
||||||
*code = bstr_cut(*code, 5);
|
*code = bstr_cut(*code, 5);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user