Fix returning invalid Unicode from parse_html.

GitOrigin-RevId: 9277022a53d23ac5c3eb1427eb48bd886b789d09
This commit is contained in:
levlam 2018-10-09 16:27:40 +03:00
parent 041896ab8d
commit 6dbef6ef76
2 changed files with 10 additions and 0 deletions

View File

@ -1616,6 +1616,12 @@ Result<vector<MessageEntity>> parse_html(string &text) {
utf16_offset += utf16_entity_length;
}
}
if (!check_utf8(result)) {
return Status::Error(400,
"Text contains invalid Unicode characters after decoding HTML entities, check for unmatched "
"surrogate code units");
}
text = result;
return entities;
}

View File

@ -2365,8 +2365,12 @@ class CliClient final : public Actor {
execute(make_tl_object<td_api::getTextEntities>(args));
} else if (op == "pte") {
send_request(make_tl_object<td_api::parseTextEntities>(args, make_tl_object<td_api::textParseModeMarkdown>()));
} else if (op == "pteh") {
send_request(make_tl_object<td_api::parseTextEntities>(args, make_tl_object<td_api::textParseModeHTML>()));
} else if (op == "ptes") {
execute(make_tl_object<td_api::parseTextEntities>(args, make_tl_object<td_api::textParseModeMarkdown>()));
} else if (op == "ptehs") {
execute(make_tl_object<td_api::parseTextEntities>(args, make_tl_object<td_api::textParseModeHTML>()));
} else if (op == "gfmt") {
send_request(make_tl_object<td_api::getFileMimeType>(trim(args)));
} else if (op == "gfe") {