1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +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
cd ../../bin
clear
./autotests
exit $?

View File

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

View File

@ -189,6 +189,26 @@ void FormCompleterTest::extractFormTest3()
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)
{
view->setHtml(html);

View File

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