Bug 23825: Koha/Object.t might fail on a backtick

If the SQL error message contains a backtick instead of a regular quote,
the regex for throwing an exception did not work.
Example:
Incorrect datetime value: 'wrong_value' for column `koha_master`.`borrowers`.`lastseen`
Note the backtics where the regex contains a regular quote.

This patch makes it more flexible: it allows one \W character before the
column name, even optional.

Test plan:
Run Koha/Object.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Marcel de Rooy 2019-10-18 09:31:10 +00:00 committed by Martin Renvoize
parent d23e50f0b2
commit 480afea9dd
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -174,11 +174,12 @@ sub store {
duplicate_id => $+{key}
);
}
elsif( $_->{msg} =~ /Incorrect (?<type>\w+) value: '(?<value>.*)' for column '(?<property>\w+)'/ ) {
elsif( $_->{msg} =~ /Incorrect (?<type>\w+) value: '(?<value>.*)' for column \W?(?<property>\S+)/ ) {
# The optional \W in the regex might be a quote or backtick
Koha::Exceptions::Object::BadValue->throw(
type => $+{type},
value => $+{value},
property => $+{property}
property => $+{property},
);
}
}