Qt: Ensure only valid input for DisplayFilter
Allow only valid inputs to be given for the name of a DisplayFilter. Specifically adding a quotation mark is not allowed Change-Id: I10454a2d23db1e0ef08148571d2762a3285e5ab8 Reviewed-on: https://code.wireshark.org/review/35006 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
8bfe73e6c6
commit
69b41e4d1e
|
@ -30,17 +30,6 @@
|
|||
#include <ui/qt/widgets/display_filter_edit.h>
|
||||
#include "wireshark_application.h"
|
||||
|
||||
// To do:
|
||||
// - Add filter expression button. The right thing to do might be to add an
|
||||
// action inside DisplayFilterEdit.
|
||||
// - Show syntax state of each filter? A partial implementation is in place
|
||||
// for capture filters.
|
||||
|
||||
enum {
|
||||
name_col_,
|
||||
filter_col_
|
||||
};
|
||||
|
||||
FilterDialog::FilterDialog(QWidget *parent, FilterType filter_type, QString new_filter_) :
|
||||
GeometryStateDialog(parent),
|
||||
ui(new Ui::FilterDialog),
|
||||
|
@ -212,11 +201,10 @@ FilterTreeDelegate::FilterTreeDelegate(QObject *parent, FilterDialog::FilterType
|
|||
filter_type_(filter_type)
|
||||
{}
|
||||
|
||||
|
||||
QWidget *FilterTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QWidget * w = Q_NULLPTR;
|
||||
if (index.column() != filter_col_) {
|
||||
if ( index.column() != FilterListModel::ColumnExpression ) {
|
||||
w = QStyledItemDelegate::createEditor(parent, option, index);
|
||||
}
|
||||
else
|
||||
|
@ -228,6 +216,9 @@ QWidget *FilterTreeDelegate::createEditor(QWidget *parent, const QStyleOptionVie
|
|||
}
|
||||
}
|
||||
|
||||
if ( qobject_cast<QLineEdit *>(w) && index.column() == FilterListModel::ColumnName )
|
||||
qobject_cast<QLineEdit *>(w)->setValidator(new FilterValidator());
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
@ -242,6 +233,21 @@ void FilterTreeDelegate::setEditorData(QWidget *editor, const QModelIndex &index
|
|||
qobject_cast<QLineEdit *>(editor)->setText(index.data().toString());
|
||||
}
|
||||
|
||||
QValidator::State FilterValidator::validate(QString & input, int & /*pos*/) const
|
||||
{
|
||||
/* Making this a list to be able to easily add additional values in the future */
|
||||
QStringList invalidKeys = QStringList() << "\"";
|
||||
|
||||
if ( input.length() <= 0 )
|
||||
return QValidator::Intermediate;
|
||||
|
||||
foreach ( QString key, invalidKeys )
|
||||
if ( input.indexOf(key) >= 0 )
|
||||
return QValidator::Invalid;
|
||||
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
|
||||
#include <ui/qt/models/filter_list_model.h>
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QValidator>
|
||||
|
||||
class QItemSelection;
|
||||
class FilterTreeDelegate;
|
||||
|
||||
|
@ -58,8 +61,6 @@ private slots:
|
|||
// Delegate for editing capture and display filters.
|
||||
//
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class FilterTreeDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -74,6 +75,12 @@ private:
|
|||
FilterDialog::FilterType filter_type_;
|
||||
};
|
||||
|
||||
class FilterValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
virtual QValidator::State validate(QString & input, int & pos) const override;
|
||||
};
|
||||
|
||||
#endif // FILTER_DIALOG_H
|
||||
|
||||
/*
|
||||
|
|
|
@ -150,6 +150,9 @@ bool FilterListModel::setData(const QModelIndex &index, const QVariant &value, i
|
|||
if ( row.count() <= index.column() )
|
||||
return false;
|
||||
|
||||
if ( index.column() == FilterListModel::ColumnName && value.toString().contains("\"") )
|
||||
return false;
|
||||
|
||||
row[index.column()] = value.toString();
|
||||
storage[index.row()] = row.join("\n");
|
||||
|
||||
|
@ -231,7 +234,7 @@ void FilterListModel::saveList()
|
|||
QTextStream out(&file);
|
||||
for ( int row = 0; row < rowCount(); row++ )
|
||||
{
|
||||
QString line = QString("\"%1\"").arg(index(row, ColumnName).data().toString().replace("\\", "\\\\").replace("\"", "\\\""));
|
||||
QString line = QString("\"%1\"").arg(index(row, ColumnName).data().toString());
|
||||
line.append(QString(" %1").arg(index(row, ColumnExpression).data().toString()));
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
Loading…
Reference in New Issue