Skip to content

Commit 46320c3

Browse files
authored
Fixes #3900, bug on MXP SEND tags (#3908)
- Bug was caused by index out of range when processing MXP SEND tags with more commands than associated hints - The solution uses HREF instead of HINT when the number of available hints is one and smaller than the number of commands
1 parent a5bc708 commit 46320c3

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/TMxpSendTagHandler.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ TMxpTagHandlerResult TMxpSendTagHandler::handleStartTag(TMxpContext& ctx, TMxpCl
4040
hints.removeFirst();
4141
}
4242

43+
// <SEND HREF="PROBE SUSPENDERS30901|BUY SUSPENDERS30901" hint="Click to see command menu">30901</SEND>
44+
if (hrefs.size() > 1 && hints.size() == 1) {
45+
hints = hrefs;
46+
}
47+
4348
// handle print to prompt feature PROMPT
4449
// <SEND "tell Zugg " PROMPT>Zugg</SEND>
4550
QString command = tag->hasAttribute(ATTR_PROMPT) ? QStringLiteral("printCmdLine") : QStringLiteral("send");
@@ -48,7 +53,9 @@ TMxpTagHandlerResult TMxpSendTagHandler::handleStartTag(TMxpContext& ctx, TMxpCl
4853
hrefs[i] = ctx.getEntityResolver().interpolate(hrefs[i]);
4954
hrefs[i] = QStringLiteral("%1([[%2]])").arg(command, hrefs[i]);
5055

51-
hints[i] = ctx.getEntityResolver().interpolate(hints[i]);
56+
if (i < hints.size()) {
57+
hints[i] = ctx.getEntityResolver().interpolate(hints[i]);
58+
}
5259
}
5360

5461
mLinkId = client.setLink(hrefs, hints);

test/TMxpSendTagHandlerTest.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,31 @@ private slots:
127127
QCOMPARE(stub.mHints[0], "say I am Gandalf");
128128
}
129129

130+
void testSendHrefHintMismatch() {
131+
// Example from starmourn on WARES command from NPCs
132+
// <SEND HREF="PROBE SUSPENDERS30901|BUY SUSPENDERS30901" hint="Click to see command menu">30901</SEND>
133+
TMxpStubContext ctx;
134+
TMxpStubClient stub;
135+
136+
TMxpTagParser parser;
137+
MxpStartTag* startTag = parser.parseStartTag(R"(<SEND HREF="PROBE SUSPENDERS30901|BUY SUSPENDERS30901" hint="Click to see command menu">)");
138+
MxpEndTag* endTag = parser.parseEndTag("</SEND>");
139+
140+
TMxpSendTagHandler sendTagHandler;
141+
TMxpTagHandler& tagHandler = sendTagHandler;
142+
tagHandler.handleTag(ctx, stub, startTag);
143+
tagHandler.handleContent("3091");
144+
tagHandler.handleTag(ctx, stub, endTag);
145+
146+
QCOMPARE(stub.mHrefs.size(), 2);
147+
QCOMPARE(stub.mHrefs[0], "send([[PROBE SUSPENDERS30901]])");
148+
QCOMPARE(stub.mHrefs[1], "send([[BUY SUSPENDERS30901]])");
149+
150+
QCOMPARE(stub.mHints.size(), 2);
151+
QCOMPARE(stub.mHints[0], "PROBE SUSPENDERS30901");
152+
QCOMPARE(stub.mHints[1], "BUY SUSPENDERS30901");
153+
}
154+
130155
};
131156

132157
#include "TMxpSendTagHandlerTest.moc"

0 commit comments

Comments
 (0)