Skip to content

Commit

Permalink
Avoid showing warnings about invalid regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Sep 5, 2023
1 parent ca8f65d commit 42c02f2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
6 changes: 1 addition & 5 deletions src/scriptable/scriptableitemselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ QVector<int> toIntVector(const QJSValue &value)

QRegularExpression toRegularExpression(const QJSValue &value)
{
// If argument is invalid/not-regexp, create an invalid regex to match nothing.
if ( !value.isRegExp() )
return QRegularExpression("(");

const QVariant variant = value.toVariant();
QRegularExpression regexp = variant.toRegularExpression();

Expand Down Expand Up @@ -136,7 +132,7 @@ QJSValue ScriptableItemSelection::selectAll()

QJSValue ScriptableItemSelection::select(const QJSValue &re, const QString &mimeFormat)
{
const QVariant regexp = re.isUndefined() ? QVariant() : toRegularExpression(re);
const QVariant regexp = re.isRegExp() ? toRegularExpression(re) : QVariant();
m_proxy->selectionSelect(m_id, regexp, mimeFormat);
return m_self;
}
Expand Down
3 changes: 0 additions & 3 deletions src/tests/testinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ class TestInterface {
/// Clean up tabs and items. Return error string on error.
virtual QByteArray cleanup() = 0;

/// Ignore given text in logs for current unit test.
virtual void setIgnoreError(const QByteArray &ignoreError) = 0;

/// Platform specific key to remove (usually Delete, Backspace on OS X).
virtual QString shortcutToRemove() = 0;

Expand Down
15 changes: 1 addition & 14 deletions src/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ bool testStderr(const QByteArray &stderrData, TestInterface::ReadStderrFlag flag
// Ignore exceptions and errors from clients in application log
// (these are expected in some tests).
static const std::vector<QRegularExpression> ignoreList{
plain("[EXPECTED-IN-TEST]"),

regex(R"(CopyQ Note \[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] <Client-[^\n]*)"),

// X11 (Linux)
Expand Down Expand Up @@ -520,8 +518,6 @@ class TestInterfaceImpl final : public TestInterface {
if (m_server) {
QCoreApplication::processEvents();
QByteArray output = readLogFile(maxReadLogSize);
if ( !m_ignoreError.isEmpty() )
output.replace(m_ignoreError, "[EXPECTED-IN-TEST] " + m_ignoreError);
if ( flag == ReadAllStderr || !testStderr(output, flag) )
return decorateOutput("Server STDERR", output);
}
Expand Down Expand Up @@ -645,16 +641,10 @@ class TestInterfaceImpl final : public TestInterface {

QByteArray cleanup() override
{
m_ignoreError.clear();
addFailedTest();
return QByteArray();
}

void setIgnoreError(const QByteArray &ignoreError) override
{
m_ignoreError = ignoreError;
}

QString shortcutToRemove() override
{
return ::shortcutToRemove();
Expand Down Expand Up @@ -771,8 +761,6 @@ class TestInterfaceImpl final : public TestInterface {
QStringList m_failed;

PlatformClipboardPtr m_clipboard;

QByteArray m_ignoreError;
};

QString keyNameFor(QKeySequence::StandardKey standardKey)
Expand Down Expand Up @@ -2272,9 +2260,8 @@ void Tests::classItemSelection()
RUN(args << "ItemSelection().select(undefined, mimeItemNotes).str()", outRows.arg("0,2"));

// Match nothing if select() argument is not a regular expression.
m_test->setIgnoreError("QtWarning: QString::contains: invalid QRegularExpression object");
RUN(args << "add" << "", "");
RUN(args << "ItemSelection().select('A').str()", outRows.arg(""));
m_test->setIgnoreError(QByteArray());
}

void Tests::classItemSelectionGetCurrent()
Expand Down

0 comments on commit 42c02f2

Please sign in to comment.