return bless \%opt, $class;
}
+
+sub _assert_pass_injection_guard {
+ if ($_[1] =~ $_[0]->{injection_guard}) {
+ my $class = ref $_[0];
+ puke "Possible SQL injection attempt '$_[1]'. If this is indeed a part of the "
+ . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own "
+ . "{injection_guard} attribute to ${class}->new()"
+ }
+}
+
+
#======================================================================
# INSERT methods
#======================================================================
$self->debug("Generic unary OP: $op - recursing as function");
- if ($op =~ $self->{injection_guard}) {
- my $class = ref $self;
-
- puke "Possible SQL injection attempt '$op'. If this is indeed a part of the "
- . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own "
- . "{injection_guard} attribute to ${class}->new()"
- }
+ $self->_assert_pass_injection_guard($op);
my ($sql, @bind) = $self->_SWITCH_refkind ($rhs, {
SCALAR => sub {
$op =~ s/^\s+|\s+$//g;# remove leading/trailing space
$op =~ s/\s+/ /g; # compress whitespace
- if ($op =~ $self->{injection_guard}) {
- my $class = ref $self;
-
- puke "Possible SQL injection attempt '$op'. If this is indeed a part of the "
- . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own "
- . "{injection_guard} attribute to ${class}->new()"
- }
-
+ $self->_assert_pass_injection_guard($op);
# so that -not_foo works correctly
$op =~ s/^not_/NOT /i;
return ${$_[1]} if ref($_[1]) eq 'SCALAR';
unless ($_[0]->{quote_char}) {
-
- if ($_[1] =~ $_[0]->{injection_guard}) {
- my $class = ref $_[0];
- puke "Possible SQL injection attempt '$_[1]'. If this is indeed a part of the "
- . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own "
- . "{injection_guard} attribute to ${class}->new()";
- }
-
+ $_[0]->_assert_pass_injection_guard($_[1]);
return $_[1];
}
$sqla->select(
'foo',
[ 'bar' ],
- { 'boby; tables' => 'bar' },
+ { 'bobby; tables' => 'bar' },
);
}, qr/Possible SQL injection attempt/, 'Injection thwarted on unquoted column' );
my ($sql, @bind) = $sqla_q->select(
'foo',
[ 'bar' ],
- { 'boby; tables' => 'bar' },
+ { 'bobby; tables' => 'bar' },
);
is_same_sql_bind (
$sql, \@bind,
- 'SELECT "bar" FROM "foo" WHERE ( "boby; tables" = ? )',
+ 'SELECT "bar" FROM "foo" WHERE ( "bobby; tables" = ? )',
[ 'bar' ],
'Correct sql with quotes on'
);