Commit c34003dc authored by dkl%redhat.com's avatar dkl%redhat.com

Bug 157092 – Implement a checking mechanism for invalid regexp

Patch by David Lawrence <dkl@redhat.com> - r/a=mkanat
parent f575fab3
......@@ -383,6 +383,15 @@ sub bz_last_key {
$table, $column);
}
sub bz_check_regexp {
my ($self, $pattern) = @_;
eval { $self->do("SELECT " . $self->sql_regexp($self->quote("a"), $pattern, 1)) };
$@ && ThrowUserError('illegal_regexp',
{ value => $pattern, dberror => $self->errstr });
}
#####################################################################
# Database Setup
#####################################################################
......
......@@ -104,13 +104,17 @@ sub bz_last_key {
}
sub sql_regexp {
my ($self, $expr, $pattern) = @_;
my ($self, $expr, $pattern, $nocheck) = @_;
$self->bz_check_regexp($pattern) if !$nocheck;
return "$expr REGEXP $pattern";
}
sub sql_not_regexp {
my ($self, $expr, $pattern) = @_;
my ($self, $expr, $pattern, $nocheck) = @_;
$self->bz_check_regexp($pattern) if !$nocheck;
return "$expr NOT REGEXP $pattern";
}
......
......@@ -95,13 +95,17 @@ sub bz_last_key {
}
sub sql_regexp {
my ($self, $expr, $pattern) = @_;
my ($self, $expr, $pattern, $nocheck) = @_;
$self->bz_check_regexp($pattern) if !$nocheck;
return "REGEXP_LIKE($expr, $pattern)";
}
sub sql_not_regexp {
my ($self, $expr, $pattern) = @_;
my ($self, $expr, $pattern, $nocheck) = @_;
$self->bz_check_regexp($pattern) if !$nocheck;
return "NOT REGEXP_LIKE($expr, $pattern)"
}
......
......@@ -93,13 +93,17 @@ sub bz_last_key {
}
sub sql_regexp {
my ($self, $expr, $pattern) = @_;
my ($self, $expr, $pattern, $nocheck) = @_;
$self->bz_check_regexp($pattern) if !$nocheck;
return "$expr ~* $pattern";
}
sub sql_not_regexp {
my ($self, $expr, $pattern) = @_;
my ($self, $expr, $pattern, $nocheck) = @_;
$self->bz_check_regexp($pattern) if !$nocheck;
return "$expr !~* $pattern"
}
......
......@@ -783,6 +783,11 @@
[% IF format %]
Please use the format '<tt>[% format FILTER html %]</tt>'.
[% END %]
[% ELSIF error == "illegal_regexp" %]
[% title = "Illegal Regular Expression" %]
The regular expression you provided [% value FILTER html %] is not valid.
The error was: [% dberror FILTER html %].
[% ELSIF error == "insufficient_data_points" %]
[% docslinks = {'reporting.html' => 'Reporting'} %]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment