Skip to content

Commit 66595c3

Browse files
committed
QTextMarkdownImporter: spell CRLF literal correctly
Amends eced22d tst_QTextMarkdownImporter::frontMatter(yaml + markdown with CRLFs) now does explicit replacement of LF with CRLF: git may convert the file, so we can't rely on the CI test system checking out a true copy of yaml-crlf.md; but QFile::open(ReadOnly | Text) ensures that we will have LF line endings, not CRLF. Pick-to: 6.8 6.9 Task-number: QTBUG-135284 Change-Id: I7eee5f41e7aea902a59ac06238e591ece016d2d3 Reviewed-by: Jan Arve Sæther <[email protected]>
1 parent 0d41b56 commit 66595c3

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

src/gui/text/qtextmarkdownimporter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static const QChar qtmi_Newline = u'\n';
2929
static const QChar qtmi_Space = u' ';
3030

3131
static constexpr auto lfMarkerString() noexcept { return "---\n"_L1; }
32-
static constexpr auto crlfMarkerString() noexcept { return "---r\n"_L1; }
32+
static constexpr auto crlfMarkerString() noexcept { return "---\r\n"_L1; }
3333

3434
// TODO maybe eliminate the margins after all views recognize BlockQuoteLevel, CSS can format it, etc.
3535
static const int qtmi_BlockQuoteIndent =

tests/auto/gui/text/qtextmarkdownimporter/data/yaml-crlf.md

-10
This file was deleted.

tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -645,27 +645,33 @@ void tst_QTextMarkdownImporter::fencedCodeBlocks()
645645
void tst_QTextMarkdownImporter::frontMatter_data()
646646
{
647647
QTest::addColumn<QString>("inputFile");
648+
QTest::addColumn<bool>("convertToCrLf");
648649
QTest::addColumn<int>("expectedFrontMatterSize");
649650
QTest::addColumn<int>("expectedBlockCount");
650651

651-
QTest::newRow("yaml + markdown") << QFINDTESTDATA("data/yaml.md") << 140 << 1;
652-
QTest::newRow("yaml + markdown with CRLFs") << QFINDTESTDATA("data/yaml-crlf.md") << 140 << 1;
653-
QTest::newRow("yaml only") << QFINDTESTDATA("data/yaml-only.md") << 59 << 0;
654-
QTest::newRow("malformed 1") << QFINDTESTDATA("data/front-marker-malformed1.md") << 0 << 1;
655-
QTest::newRow("malformed 2") << QFINDTESTDATA("data/front-marker-malformed2.md") << 0 << 2;
656-
QTest::newRow("malformed 3") << QFINDTESTDATA("data/front-marker-malformed3.md") << 0 << 1;
652+
QTest::newRow("yaml + markdown") << QFINDTESTDATA("data/yaml.md") << false << 140 << 1;
653+
QTest::newRow("yaml + markdown with CRLFs") << QFINDTESTDATA("data/yaml.md") << true << 147 << 1;
654+
QTest::newRow("yaml only") << QFINDTESTDATA("data/yaml-only.md") << false << 59 << 0;
655+
QTest::newRow("malformed 1") << QFINDTESTDATA("data/front-marker-malformed1.md") << false << 0 << 1;
656+
QTest::newRow("malformed 2") << QFINDTESTDATA("data/front-marker-malformed2.md") << false << 0 << 2;
657+
QTest::newRow("malformed 3") << QFINDTESTDATA("data/front-marker-malformed3.md") << false << 0 << 1;
657658
}
658659

659660
void tst_QTextMarkdownImporter::frontMatter()
660661
{
661662
QFETCH(QString, inputFile);
663+
QFETCH(bool, convertToCrLf);
662664
QFETCH(int, expectedFrontMatterSize);
663665
QFETCH(int, expectedBlockCount);
664666

665667
QFile f(inputFile);
666668
QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text));
667669
QString md = QString::fromUtf8(f.readAll());
668670
f.close();
671+
if (convertToCrLf)
672+
md.replace("\n", "\r\n");
673+
qCDebug(lcTests) << inputFile << "begins with" << md.first(16).toLatin1().toHex(' ');
674+
669675
const int yamlBegin = md.indexOf("name:");
670676
const int yamlEnd = md.indexOf("---", yamlBegin);
671677
const QString yaml = md.sliced(yamlBegin, yamlEnd - yamlBegin);

0 commit comments

Comments
 (0)