Commit b7a8c03f authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Let canonicalization return a failure message

This allows CF creation to abort on invalid values, and HasEntry to give
up and move on if passed a value that can never be found in the
database.
parent c1727f60
......@@ -1701,10 +1701,10 @@ sub _CanonicalizeValue {
my $args = shift;
my $type = $self->_Value('Type');
return unless $type;
return 1 unless $type;
my $method = '_CanonicalizeValue'. $type;
return unless $self->can($method);
return 1 unless $self->can($method);
$self->$method($args);
}
......@@ -1715,6 +1715,7 @@ sub _CanonicalizeValueDateTime {
$DateObj->Set( Format => 'unknown',
Value => $args->{'Content'} );
$args->{'Content'} = $DateObj->ISO;
return 1;
}
# For date, we need to store Content as ISO date
......@@ -1729,6 +1730,7 @@ sub _CanonicalizeValueDate {
Value => $args->{'Content'},
);
$args->{'Content'} = $DateObj->Date( Timezone => 'user' );
return 1;
}
sub _CanonicalizeValueIPAddress {
......@@ -1736,6 +1738,9 @@ sub _CanonicalizeValueIPAddress {
my $args = shift;
$args->{Content} = RT::ObjectCustomFieldValue->ParseIP( $args->{Content} );
return (0, $self->loc("Content is not a valid IP address"))
unless $args->{Content};
return 1;
}
sub _CanonicalizeValueIPAddressRange {
......@@ -1749,6 +1754,9 @@ sub _CanonicalizeValueIPAddressRange {
= RT::ObjectCustomFieldValue->ParseIPRange( $content );
$args->{ContentType} = 'text/plain';
return (0, $self->loc("Content is not a valid IP address range"))
unless $args->{Content};
return 1;
}
=head2 MatchPattern STRING
......
......@@ -85,7 +85,8 @@ sub Create {
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $args{CustomField} );
$cf->_CanonicalizeValue(\%args);
my ($val, $msg) = $cf->_CanonicalizeValue(\%args);
return ($val, $msg) unless $val;
if ( defined $args{'Content'} && length( Encode::encode_utf8($args{'Content'}) ) > 255 ) {
if ( defined $args{'LargeContent'} && length $args{'LargeContent'} ) {
......
......@@ -135,7 +135,8 @@ sub HasEntry {
my $args = $canon_value{ $cf->Type };
if ( !$args ) {
$args = { Content => $value, LargeContent => $large_content };
$cf->_CanonicalizeValue( $args );
my ($ok, $msg) = $cf->_CanonicalizeValue( $args );
next unless $ok;
$canon_value{ $cf->Type } = $args;
}
......
Supports Markdown
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