Skip to content

Commit

Permalink
#2959 fix: code block comment overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Feb 16, 2024
1 parent 7dbed26 commit b8783d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# QOwnNotes Changelog

## 24.2.4
- fixed a crash, when someone enters a misplaced comment marker directly before
the closing mark of the code block (for [#2959](https://github.com/pbek/QOwnNotes/issues/2959))

## 24.2.3
- support was added for the **QOwnNotes Web Companion browser extension**
to also allow deleting of bookmarks in the current note
Expand Down
12 changes: 11 additions & 1 deletion src/helpers/codetohtmlconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,17 @@ int CodeToHtmlConverter::highlightComment(StringView input, QString &output, int
endPos += 2;
}
}
output += setFormat(input.mid(i, endPos - i), Format::Comment);

auto commentEndPos = endPos - i;
if (commentEndPos >= -1) {
output += setFormat(input.mid(i, commentEndPos), Format::Comment);
} else {
// Emergency escape, if someone enters a misplaced comment marker
// directly before the closing mark of the code block
// See: https://github.com/pbek/QOwnNotes/issues/2959
return i;
};

i = endPos;
// escape the endline
if (endPos < input.length()) output += escape(input.at(endPos));
Expand Down

0 comments on commit b8783d9

Please sign in to comment.