[PyQt] Bug with empty string in QWebPage::javaScriptPrompt
Florian Bruhin
me at the-compiler.org
Sat Jun 14 20:59:02 BST 2014
I think I found a bug with QWebPage::javaScriptPrompt using
Qt/PyQt 5.2.1, Qt runtime 5.3.0 and Python 3.4.
When overriding QWebPage::javaScriptPrompt and returning an empty
string, javascript gets some random RAM content back it seems. This
also might be a security issue...
When I run super().javaScriptPrompt, (True, '') is returned when I
enter an empty string in the dialog as well, so what I return seems to
be correct.
Example script which simply gets a value via prompt(), returns it to
javascript, and prints it to the terminal via alert(), then garbage is
printed to the terminal:
# ======
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
HTML = """
<html>
<head>
<script type="text/javascript">
function prompter() {
var reply = prompt("Test", "")
alert( "Answer: " + reply)
}
</script>
</head>
<body>
<input type="button" onclick="prompter()" value="Test">
</body>
</html>
"""
class WebPage(QWebPage):
def javaScriptPrompt(self, frame, msg, default):
return True, ''
def javaScriptAlert(self, frame, msg):
print("alert: {}".format(msg.encode('ASCII', errors='backslashreplace')))
return
app = QApplication([])
view = QWebView()
page = WebPage()
view.setPage(page)
view.setHtml(HTML)
view.show()
app.exec_()
# ======
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140614/99fecfed/attachment.sig>
More information about the PyQt
mailing list