diff options
-rw-r--r-- | perllib/Open311.pm | 12 | ||||
-rw-r--r-- | t/open311.t | 6 |
2 files changed, 16 insertions, 2 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm index a65e19fa6..4ec0679af 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -126,7 +126,7 @@ sub _populate_service_request_params { $description = $problem->detail; } - my ( $firstname, $lastname ) = ( $problem->name =~ /(\w+)\.?\s+(.+)/ ); + my ( $firstname, $lastname ) = $self->split_name( $problem->name ); my $params = { description => $description, @@ -338,7 +338,7 @@ sub _populate_service_request_update_params { my $comment = shift; my $name = $comment->name || $comment->user->name; - my ( $firstname, $lastname ) = ( $name =~ /(\w+)\.?\s+(.+)/ ); + my ( $firstname, $lastname ) = $self->split_name( $name ); $lastname ||= '-'; # fall back to problem state as it's probably correct @@ -410,6 +410,14 @@ sub _populate_service_request_update_params { return $params; } +sub split_name { + my ( $self, $name ) = @_; + + my ( $first, $last ) = ( $name =~ /(\w+)(?:\.?\s+(.+))?/ ); + + return ( $first, $last ); +} + sub _get { my $self = shift; my $path = shift; diff --git a/t/open311.t b/t/open311.t index 35d9b0ecb..ce18a6d0c 100644 --- a/t/open311.t +++ b/t/open311.t @@ -196,6 +196,12 @@ for my $test ( first_name => 'Nom', last_name => 'de Report', }, + { + desc => 'Check single word name handled correctly', + name => 'Nom', + first_name => 'Nom', + last_name => '', + } ) { subtest $test->{desc} => sub { $problem->extra( undef ); |