summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2024-03-04 13:30:14 -0700
committerShawn Rutledge <shawn.rutledge@qt.io>2024-03-05 16:12:33 -0700
commitd14eec536da0504170c14bdfc5a5d7295032ea3f (patch)
tree2df64da3afe6ffc39be65c386c57b59f38500f72 /src/gui/text
parent81f174d79659a08d481cb6e816e6c1230ad61c09 (diff)
QTextMarkdownImporter::import(): don't crash if file has only yaml
If a markdown file has FrontMatter, we look for the end of the newlines after the `---` marker to begin parsing the actual markdown. But check bounds in case the file contains only front matter and not markdown. Fixes: QTBUG-122982 Change-Id: I09c4ae90c47ebd84877738aecc1d1cad0b0bfca2 Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextmarkdownimporter.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp
index c9aac01fa9..511c0883a4 100644
--- a/src/gui/text/qtextmarkdownimporter.cpp
+++ b/src/gui/text/qtextmarkdownimporter.cpp
@@ -148,7 +148,7 @@ void QTextMarkdownImporter::import(const QString &markdown)
++firstLinePos;
QByteArray frontMatter = md.sliced(firstLinePos, endMarkerPos - firstLinePos);
firstLinePos = endMarkerPos + 4; // first line of markdown after yaml
- while (md.at(firstLinePos) == '\n' || md.at(firstLinePos) == '\r')
+ while (md.size() > firstLinePos && (md.at(firstLinePos) == '\n' || md.at(firstLinePos) == '\r'))
++firstLinePos;
md.remove(0, firstLinePos);
doc->setMetaInformation(QTextDocument::FrontMatter, QString::fromUtf8(frontMatter));