ITADN

Mismatch Between Text Modification and Indexing in QMarkdownTextEdit::handleBracketClosing Causing Failure

#207Closedcom3dian 创建于 2024-08-02
C
com3diancommented
### Issue Description: https://github.com/pbek/qmarkdowntextedit/blob/9af9c413dd1c7c8b314acfa6a0151b1e9d099c55/qmarkdowntextedit.cpp#L716-L720 In the method `QMarkdownTextEdit::handleBracketClosing`, the selected text within a block has its leading white-spaces removed. However, the index pib does not account for these white-spaces, which can result in an `ASSERT: "pos <= d.size"` error in QString and potentially crash the software when code like `text.at(pib - 1)` is executed. ### To fix ```c++ const QString text = cursor.block().text().remove(QRegularExpression("^\\s+")); const int pib = cursor.positionInBlock() - cursor.block().text().length() + text.length(); ``` ### Note *I'm a beginner in cpp and qt, so please correct me if I'm wrong.* Thanks for this awesome project!
关闭于 2024-08-04 3 条评论