Fix Message Components for Tags with Attributes
Don't assume that the close tag is the length of the start tag +1 BUG: 482331
This commit is contained in:
@@ -529,6 +529,19 @@ void TextHandlerTest::componentOutput_data()
|
||||
QTest::newRow("inline code single block") << QStringLiteral("<code>https://kde.org</code>")
|
||||
<< QList<MessageComponent>{
|
||||
MessageComponent{MessageComponentType::Text, QStringLiteral("<code>https://kde.org</code>"), {}}};
|
||||
QTest::newRow("long start tag")
|
||||
<< QStringLiteral(
|
||||
"Ah, you mean something like<br/><pre data-md=\"```\"><code class=\"language-qml\"># main.qml\nimport CustomQml\n...\nControls.TextField { id: "
|
||||
"someField }\nCustomQml {\n someTextProperty: someField.text\n}\n</code></pre>Sure you can, it's still local to the same file where you "
|
||||
"defined the id")
|
||||
<< QList<MessageComponent>{
|
||||
MessageComponent{MessageComponentType::Text, QStringLiteral("Ah, you mean something like"), {}},
|
||||
MessageComponent{
|
||||
MessageComponentType::Code,
|
||||
QStringLiteral(
|
||||
"# main.qml\nimport CustomQml\n...\nControls.TextField { id: someField }\nCustomQml {\n someTextProperty: someField.text\n}"),
|
||||
QVariantMap{{QStringLiteral("class"), QStringLiteral("qml")}}},
|
||||
MessageComponent{MessageComponentType::Text, QStringLiteral("Sure you can, it's still local to the same file where you defined the id"), {}}};
|
||||
}
|
||||
|
||||
void TextHandlerTest::componentOutput()
|
||||
|
||||
@@ -307,13 +307,14 @@ int TextHandler::nextBlockPos(const QString &string)
|
||||
return string.size();
|
||||
}
|
||||
|
||||
int closeTagPos = string.indexOf(QStringLiteral("</%1>").arg(tagType));
|
||||
const auto closeTag = QStringLiteral("</%1>").arg(tagType);
|
||||
int closeTagPos = string.indexOf(closeTag);
|
||||
// If the close tag can't be found assume malformed html and process as single block.
|
||||
if (closeTagPos == -1) {
|
||||
return string.size();
|
||||
}
|
||||
|
||||
return closeTagPos + tag.size() + 1;
|
||||
return closeTagPos + closeTag.size();
|
||||
}
|
||||
|
||||
MessageComponent TextHandler::nextBlock(const QString &string,
|
||||
|
||||
Reference in New Issue
Block a user