diff options
author | Michal Klocek <michal.klocek@qt.io> | 2023-06-06 18:22:43 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2023-06-08 17:04:33 +0200 |
commit | fb9bc02df6114ae9de15ae8267fc2dac79144aa0 (patch) | |
tree | 74c017dc67270d0bf73c02af6cbab628f556f0b5 /tests/auto/widgets | |
parent | 5afe39d0bf1b1e181b5a1c91774f92dbc6013ed5 (diff) |
Fix crashes on sendEvent on 'invalid' key.text
A user can create QKeyEvent which may have too long
QKeyEvent::text and does not fit into null terminated blink
WebKeyboardEvent::text. Till now the text was mem copied
however without null-termination if it was too long
(which is char16_t[WebKeyboardEvent::kTextLengthCap])
It seems that real keyboard events do not generate any 'key.text'
for modifiers, however user can provide any text (for example
in the form of 'shift' 'control'). Therefore 'alt' still
worked as we had 16 bytes of space but 'shift' was already
too long.
In case we can not fit into blink web keyboard event text
with null terminated string simply skip the text
as it is not there in the first place in case of non-user
generated key events. This way the text is always
null-terminated.
Pick-to: 6.6 6.5 5.15
Fixes: QTBUG-113704
Change-Id: Ib1560a44e7451ab7d886c72338b7433fc51318ed
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 15e226139..c242d240e 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -183,6 +183,7 @@ private Q_SLOTS: void navigateOnDrop_data(); void navigateOnDrop(); void datalist(); + void longKeyEventText(); }; // This will be called before the first test function is executed. @@ -3785,5 +3786,49 @@ void tst_QWebEngineView::datalist() QStringLiteral("fil")); } +class ConsolePage : public QWebEnginePage +{ + Q_OBJECT +public: + ConsolePage(QObject *parent = nullptr) : QWebEnginePage(parent) { } + void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, + int lineNumber, const QString &sourceID) override + { + Q_UNUSED(level) + Q_UNUSED(lineNumber) + Q_UNUSED(sourceID) + if (message.contains("TEST_KEY:Shift")) + emit done(); + } +signals: + void done(); +}; + +//qtbug_113704 +void tst_QWebEngineView::longKeyEventText() +{ + const QString html(QStringLiteral("<html><body><p>TEST</p>" + "<script>" + "document.addEventListener('keydown', (event)=> {" + "console.log('TEST_KEY:' + event.key);" + "});" + "</script>" + "</body></html>")); + + QWebEngineView view; + ConsolePage page; + view.setPage(&page); + QSignalSpy loadFinishedSpy(view.page(), &QWebEnginePage::loadFinished); + view.resize(200, 400); + view.show(); + view.setHtml(html); + QTRY_VERIFY(loadFinishedSpy.size()); + QSignalSpy consoleMessageSpy(&page, &ConsolePage::done); + Qt::Key key(Qt::Key_Shift); + QKeyEvent event(QKeyEvent::KeyPress, key, Qt::NoModifier, QKeySequence(key).toString()); + QApplication::sendEvent(view.focusProxy(), &event); + QTRY_VERIFY(consoleMessageSpy.size()); +} + QTEST_MAIN(tst_QWebEngineView) #include "tst_qwebengineview.moc" |