[EP-tech] Re: Email MetaField validation

Tim Brody tdb2 at ecs.soton.ac.uk
Wed Apr 18 11:45:28 BST 2012


On Wed, 2012-04-18 at 16:10 +1000, Matthew Kerwin wrote:
> In our ePrints installation we decided to make things a little easier
>  on the human when importing eprints, by relaxing validation to allow
>  leading and trailing whitespace.  To accommodate this relaxation I
>  modified EPrints::MetaField::Email, adding a form_value_basic method
>  that subsequently strips said whitespace, thus:
> 
> ----------
> sub form_value_basic
> {
> 	my $self = shift;
> 	my $v = $self->SUPER::form_value_basic( @_ );
> 	# strip leading and trailing whitespace
> 	$v =~ s/^\s+|\s+$//g;
> 	return $v;
> }
> ----------
>
> Is this the right approach, or is there a better point where I can
>  intercept the data before it hits our back-end store?  And if this is
>  the right place for sanitisation, should the method be patched in
>  upstream?

If you wanted to override a single field you could set its "fromform"
property.

Either way, the "form_value_basic" method is unlikely to change anytime
soon, so you should be safe overriding that method.

> Further, is there a reason that any meta-field would ever want leading
>  and trailing whitespace?  Whatever approach ends up being used to
>  sanitise the data, should it apply to all meta-fields, or just email?

I have pondered this before. I think I was just scared about making such
a wide-ranging change :-)

-- 
All the best,
Tim
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part
Url : http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20120418/d5638d63/attachment-0001.bin 


More information about the Eprints-tech mailing list