1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Properly export form data if password input is the only input in form.

This commit is contained in:
nowrep 2013-01-31 21:29:30 +01:00
parent 4f3c8b0d00
commit 4fc6686185
4 changed files with 27 additions and 6 deletions

View File

@ -5,5 +5,5 @@ cd ../tests/autotests
qmake DEFINES+=NO_SYSTEM_DATAPATH && make qmake DEFINES+=NO_SYSTEM_DATAPATH && make
cd ../../bin cd ../../bin
clear
./autotests ./autotests
exit $?

View File

@ -43,6 +43,10 @@ PageFormData PageFormCompleter::extractFormData(const QByteArray &postData) cons
QByteArray data = convertWebKitFormBoundaryIfNecessary(postData); QByteArray data = convertWebKitFormBoundaryIfNecessary(postData);
PageFormData formData = {false, QString(), QString(), data}; PageFormData formData = {false, QString(), QString(), data};
if (data.isEmpty()) {
return formData;
}
if (!data.contains('=')) { if (!data.contains('=')) {
qDebug() << "PageFormCompleter: Invalid form data" << data; qDebug() << "PageFormCompleter: Invalid form data" << data;
return formData; return formData;
@ -88,7 +92,7 @@ PageFormData PageFormCompleter::extractFormData(const QByteArray &postData) cons
<< "input[type=\"text\"][name*=\"name\"]" << "input[type=\"text\"][name*=\"name\"]"
<< "input[type=\"text\"]" << "input[type=\"text\"]"
<< "input[type=\"email\"]" << "input[type=\"email\"]"
<< "input:not([type=\"hidden\"])"; << "input:not([type=\"hidden\"][type=\"password\"])";
foreach(const QString & selector, selectors) { foreach(const QString & selector, selectors) {
const QWebElementCollection &inputs = foundForm.findAll(selector); const QWebElementCollection &inputs = foundForm.findAll(selector);
@ -107,10 +111,6 @@ PageFormData PageFormCompleter::extractFormData(const QByteArray &postData) cons
} }
} }
if (!found) {
return formData;
}
formData.found = true; formData.found = true;
formData.username = usernameValue; formData.username = usernameValue;
formData.password = passwordValue; formData.password = passwordValue;

View File

@ -189,6 +189,26 @@ void FormCompleterTest::extractFormTest3()
QCOMPARE(form.password, QString("tst_password")); QCOMPARE(form.password, QString("tst_password"));
} }
void FormCompleterTest::extractFormTest4()
{
// Test extracting form that contains only password
// as editable input
QByteArray data = "username=tst_username&password=tst_password";
QString html = "<form name='form2' method='post' action='foo2.php'>"
"<input id='id3' type='hidden' name='username' value='tst_username'>"
"<input id='id4' type='password' name='password' value='tst_password'>"
"<input type='submit' value='submit' name='submit'>"
"</form>";
PageFormData form = extractFormData(html, data);
QVERIFY(form.found == true);
QCOMPARE(form.username, QString());
QCOMPARE(form.password, QString("tst_password"));
}
void FormCompleterTest::completeWithData(const QString &html, const QByteArray &data) void FormCompleterTest::completeWithData(const QString &html, const QByteArray &data)
{ {
view->setHtml(html); view->setHtml(html);

View File

@ -41,6 +41,7 @@ private slots:
void extractFormTest1(); void extractFormTest1();
void extractFormTest2(); void extractFormTest2();
void extractFormTest3(); void extractFormTest3();
void extractFormTest4();
private: private:
void completeWithData(const QString &html, const QByteArray &data); void completeWithData(const QString &html, const QByteArray &data);