diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 319814a3e..00cb8d512 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -130,7 +130,7 @@ QStringList AutoType::windowTitles() return m_plugin->windowTitles(); } -void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QString& customSequence, WId window) +void AutoType::_performAutoType(const Entry* entry, QWidget* hideWindow, const QString& customSequence, WId window) { if (m_inAutoType || !m_plugin) { return; @@ -253,7 +253,7 @@ void AutoType::performAutoTypeFromGlobal(Entry* entry, const QString& sequence) m_inAutoType = false; - performAutoTypeWithSyntaxCheckingDialog(entry, nullptr, sequence, m_windowFromGlobal); + performAutoType(entry, nullptr, sequence, m_windowFromGlobal); } void AutoType::resetInAutoType() @@ -556,14 +556,6 @@ QList AutoType::createActionFromTemplate(const QString& tmpl, c } } - //allows to insert usernames and passwords multiple times - if (!list.isEmpty()) { - for (int i = 1; i < num; i++) { - for (int j = 0; j < resolved.size(); j++) { - list.append(list.at(j)->clone()); - } - } - } return list; } @@ -679,13 +671,13 @@ bool AutoType::windowMatchesUrl(const QString& windowTitle, const QString& resol bool AutoType::checkSyntax(const QString &string) { //checks things like {word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{-}~+%@fixedstring - QString allowRepetition = "(\\s[0-9]*){0,1}"; + QString allowRepetition = "(\\s\\d*){0,1}"; QString normalCommands = "[A-Z:]*" + allowRepetition; //the ":" allows custom commands QString specialLiterals = "[\\^\\%\\(\\)~\\{\\}\\[\\]\\+-]" + allowRepetition; QString functionKeys = "(F[1-9]" + allowRepetition + "|F1[0-2])" + allowRepetition; - QString numpad = "NUMPAD[0-9]" + allowRepetition; - QString delay = "DELAY=[0-9]+"; - QString beep = "BEEP\\s[0-9]*\\s[0-9]*"; + QString numpad = "NUMPAD\\d" + allowRepetition; + QString delay = "DELAY=\\d+"; + QString beep = "BEEP\\s\\d*\\s\\d*"; QString vkey = "VKEY(-[EN]X){0,1}" + allowRepetition; //these arent in parenthesis @@ -703,7 +695,7 @@ bool AutoType::checkSyntax(const QString &string) bool AutoType::checkHighDelay(const QString &string) { - QRegExp highDelay(".*\\{Delay\\s[0-9]{5,}\\}.*"); //5 digit numbers(10 seconds) are too much + QRegExp highDelay("\\{DELAY\\s\\d{5,}\\}"); //5 digit numbers(10 seconds) are too much highDelay.setCaseSensitivity(Qt::CaseInsensitive); highDelay.setPatternSyntax(QRegExp::RegExp); return highDelay.exactMatch(string); @@ -711,16 +703,14 @@ bool AutoType::checkHighDelay(const QString &string) bool AutoType::checkHighRepetition(const QString &string) { - QRegExp highRepetition(".*\\s[0-9]{3,}.*");//3 digit numbers are too much + QRegExp highRepetition("\\{(?!DELAY\\s)\\w*\\s\\d{3,}\\}"); //3 digit numbers are too much + highRepetition.setCaseSensitivity(Qt::CaseInsensitive); highRepetition.setPatternSyntax(QRegExp::RegExp); return highRepetition.exactMatch(string); } void -AutoType::performAutoTypeWithSyntaxCheckingDialog(const Entry *entry, - QWidget *hideWindow, - const QString &customSequence, - WId window) +AutoType::performAutoType(const Entry *entry, QWidget *hideWindow, const QString &customSequence, WId window) { if (!AutoType::checkSyntax(entry->effectiveAutoTypeSequence())) { QMessageBox messageBox; @@ -747,6 +737,6 @@ AutoType::performAutoTypeWithSyntaxCheckingDialog(const Entry *entry, return; } } - performAutoType(entry, hideWindow, customSequence, window); + _performAutoType(entry, hideWindow, customSequence, window); } diff --git a/src/autotype/AutoType.h b/src/autotype/AutoType.h index 90d12a7f6..8aff7a947 100644 --- a/src/autotype/AutoType.h +++ b/src/autotype/AutoType.h @@ -37,7 +37,7 @@ class AutoType : public QObject public: QStringList windowTitles(); - void performAutoType(const Entry* entry, QWidget* hideWindow = nullptr, + void _performAutoType(const Entry* entry, QWidget* hideWindow = nullptr, const QString& customSequence = QString(), WId window = 0); bool registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); void unregisterGlobalShortcut(); @@ -45,10 +45,8 @@ public: static bool checkSyntax(const QString &string); static bool checkHighRepetition(const QString &string); static bool checkHighDelay(const QString &string); - void performAutoTypeWithSyntaxCheckingDialog(const Entry *entry, - QWidget *hideWindow = nullptr, - const QString &customSequence = QString(), - WId window = 0); + void performAutoType(const Entry *entry, QWidget *hideWindow = nullptr, + const QString &customSequence = QString(), WId window = 0); inline bool isAvailable() { return m_plugin; diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 3f5222e1d..387d5d2a2 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -584,7 +584,7 @@ void DatabaseWidget::performAutoType() return; } - autoType()->performAutoTypeWithSyntaxCheckingDialog(currentEntry, window()); + autoType()->performAutoType(currentEntry, window()); } void DatabaseWidget::openUrl() diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 171590513..fdb8aa142 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -32,8 +32,8 @@ #include #include #include -#include +#include "autotype/AutoType.h" #include "core/Config.h" #include "core/Database.h" #include "core/Entry.h" diff --git a/tests/TestAutoType.cpp b/tests/TestAutoType.cpp index acc2df61f..d1c09c263 100644 --- a/tests/TestAutoType.cpp +++ b/tests/TestAutoType.cpp @@ -282,3 +282,18 @@ void TestAutoType::testGlobalAutoTypeRegExp() QCOMPARE(m_test->actionChars(), QString("custom_attr_third")); m_test->clearActions(); } + +void TestAutoType::testAutoTypeSyntaxChecks() +{ + // Huge sequence + QCOMPARE(true, AutoType::checkSyntax("{word 23}{F1 23}{~ 23}{% 23}{^}{F12}{(}{) 23}{[}{[}{]}{Delay=23}{+}{-}~+%@fixedstring")); + // Bad sequence + QCOMPARE(false, AutoType::checkSyntax("{{{}}{}{}}{{}}")); + // High DelAY / low delay + QCOMPARE(true, AutoType::checkHighDelay("{DelAY 50000}")); + QCOMPARE(false, AutoType::checkHighDelay("{delay 50}")); + // Many repetition / few repetition / delay not repetition + QCOMPARE(true, AutoType::checkHighRepetition("{LEFT 50000000}")); + QCOMPARE(false, AutoType::checkHighRepetition("{SPACE 10}{TAB 3}{RIGHT 50}")); + QCOMPARE(false, AutoType::checkHighRepetition("{delay 5000000000}")); +} \ No newline at end of file diff --git a/tests/TestAutoType.h b/tests/TestAutoType.h index 0cd4a5bdd..b7c33823b 100644 --- a/tests/TestAutoType.h +++ b/tests/TestAutoType.h @@ -47,6 +47,7 @@ private slots: void testGlobalAutoTypeUrlSubdomainMatch(); void testGlobalAutoTypeTitleMatchDisabled(); void testGlobalAutoTypeRegExp(); + void testAutoTypeSyntaxChecks(); private: AutoTypePlatformInterface* m_platform;