From 5e1efca0404a8939315078eaf6350e2810886cce Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 3 Dec 2023 00:58:45 +1100 Subject: [PATCH] "Fix" crash on empty text https://ruby.social/@CoralineAda/109951421922797743 --- servehelper.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/servehelper.cpp b/servehelper.cpp index aa421b3..602902f 100644 --- a/servehelper.cpp +++ b/servehelper.cpp @@ -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;