"Fix" crash on empty text

https://ruby.social/@CoralineAda/109951421922797743
This commit is contained in:
blankie 2023-12-03 00:58:45 +11:00
parent 6cb53f1bc1
commit 5e1efca040
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 8 additions and 2 deletions

View File

@ -204,7 +204,9 @@ std::string get_text_content(lxb_dom_node_t* child) {
while (remove_from && out[remove_from - 1] == '\n') {
remove_from--;
}
if (out.size() > remove_from) {
// Don't engulf everything, otherwise it crashes
// https://ruby.social/@CoralineAda/109951421922797743
if (out.size() > remove_from && remove_from != 0) {
out.erase(remove_from);
}
}
@ -213,7 +215,11 @@ std::string get_text_content(lxb_dom_node_t* child) {
while (out.size() > remove_to && out[remove_to] == '\n') {
remove_to++;
}
out.erase(0, remove_to);
// Don't engulf everything, otherwise it crashes
// https://ruby.social/@CoralineAda/109951421922797743
if (out.size() > remove_to) {
out.erase(0, remove_to);
}
}
return out;