[mb-commits] branch, mbs-5535, created. MBS-5535, correctly collapse and trim all parts of an artist credit in Edit ::...
MusicBrainz Git Server <[email protected]>
| Newsgroups | gmane.comp.audio.musicbrainz.cvs |
|---|---|
| Message-ID | <E1TTbna-0006w1-Em@wiley> |
The branch, mbs-5535 has been created
at 2e6ac22d2513a609c8be781ec6f3a1363cdf1ad3 (commit)
- Log -----------------------------------------------------------------
commit 2e6ac22d2513a609c8be781ec6f3a1363cdf1ad3
Author: warp <[email protected]>
Date: Wed Oct 31 17:09:53 2012 +0100
MBS-5535, correctly collapse and trim all parts of an artist credit in Edit::Utils::clean_submitted_artist_credits.
diff --git a/lib/MusicBrainz/Server/Data/Utils.pm b/lib/MusicBrainz/Server/Data/Utils.pm
index 4d57340..03a7e6b 100644
--- a/lib/MusicBrainz/Server/Data/Utils.pm
+++ b/lib/MusicBrainz/Server/Data/Utils.pm
@@ -23,6 +23,7 @@ our @EXPORT_OK = qw(
artist_credit_to_ref
check_data
check_in_use
+ clean_text
copy_escape
defined_hash
generate_gid
@@ -309,9 +310,8 @@ sub add_partial_date_to_row
}
}
-sub trim {
- # Remove leading and trailing space
- my $t = Text::Trim::trim (shift);
+sub clean_text {
+ my $t = shift;
# Compress whitespace
$t =~ s/\s+/ /g;
@@ -322,6 +322,13 @@ sub trim {
return $t;
}
+sub trim {
+ # Remove leading and trailing space
+ my $t = Text::Trim::trim (shift);
+
+ return clean_text ($t);
+}
+
sub type_to_model
{
return $TYPE_TO_MODEL{$_[0]} || die "$_[0] is not a type that has a model";
diff --git a/lib/MusicBrainz/Server/Edit/Utils.pm b/lib/MusicBrainz/Server/Edit/Utils.pm
index 9f8a1f6..73edf8c 100644
--- a/lib/MusicBrainz/Server/Edit/Utils.pm
+++ b/lib/MusicBrainz/Server/Edit/Utils.pm
@@ -5,12 +5,11 @@ use 5.10.0;
use List::MoreUtils qw( uniq );
-use MusicBrainz::Server::Data::Utils qw( partial_date_to_hash artist_credit_to_ref );
+use MusicBrainz::Server::Data::Utils qw( artist_credit_to_ref clean_text trim partial_date_to_hash );
use MusicBrainz::Server::Entity::ArtistCredit;
use MusicBrainz::Server::Entity::ArtistCreditName;
use MusicBrainz::Server::Edit::Exceptions;
use MusicBrainz::Server::Constants qw( :edit_status :vote $AUTO_EDITOR_FLAG :quality :expire_action );
-use Text::Trim qw( trim );
use MusicBrainz::Server::Translation qw( N_l );
@@ -189,6 +188,10 @@ sub clean_submitted_artist_credits
# Set to empty string if join_phrase is undef.
$part->{join_phrase} = '' unless defined $part->{join_phrase};
+ $part->{join_phrase} = clean_text ($part->{join_phrase});
+
+ # Remove trailing whitespace from a trailing join phrase.
+ $part->{join_phrase} =~ s/\s+$// if $_ == $#names;
}
elsif (! $part)
{
diff --git a/t/lib/t/MusicBrainz/Server/Edit/Utils.pm b/t/lib/t/MusicBrainz/Server/Edit/Utils.pm
new file mode 100644
index 0000000..265a715
--- /dev/null
+++ b/t/lib/t/MusicBrainz/Server/Edit/Utils.pm
@@ -0,0 +1,71 @@
+package t::MusicBrainz::Server::Edit::Utils;
+use Test::Routine;
+use Test::More;
+use MusicBrainz::Server::Edit::Utils qw( clean_submitted_artist_credits );
+
+test 'clean_submitted_artist_credits, copy name to credit' => sub {
+
+ my $ac = {
+ names => [
+ {
+ artist => { name => "J Alvarez" },
+ join_phrase => " feat. ",
+ },
+ {
+ artist => { name => "Voltio" },
+ name => "Julio Voltio",
+ }]
+ };
+
+ my $expected = {
+ names => [
+ {
+ artist => { name => "J Alvarez" },
+ name => "J Alvarez",
+ join_phrase => " feat. ",
+ },
+ {
+ artist => { name => "Voltio" },
+ name => "Julio Voltio",
+ join_phrase => "",
+ }]
+ };
+
+ is_deeply ( clean_submitted_artist_credits ($ac),
+ $expected, "copied name to credits" );
+};
+
+test 'clean_submitted_artist_credits, trim and collapse all fields' => sub {
+
+ my $ac = {
+ names => [
+ {
+ artist => { name => " J Alvarez " },
+ join_phrase => " feat. ",
+ },
+ {
+ artist => { name => " Voltio " },
+ name => " Julio Voltio ",
+ join_phrase => "!!!11~ ",
+ }]
+ };
+
+ my $expected = {
+ names => [
+ {
+ artist => { name => "J Alvarez" },
+ name => "J Alvarez",
+ join_phrase => " feat. ",
+ },
+ {
+ artist => { name => "Voltio" },
+ name => "Julio Voltio",
+ join_phrase => "!!!11~",
+ }]
+ };
+
+ is_deeply ( clean_submitted_artist_credits ($ac),
+ $expected, "trimmed and collapsed" );
+};
+
+1;
-----------------------------------------------------------------------
hooks/post-receive
--
mb_server