Skip to content

Commit 4a2913b

Browse files
committed
Merge branch 'production'
* production: MBS-11461: Add TO_JSON to ExampleRelationships MBS-11445: Fix 502 on auto-editor election pages MBS-11447: Use to_json_object on language in Work::Create Standardise building display entity in ::Create edits MBS-11448: Pass Place->new() call through to_json_object Remove multiple blank lines from annotation MBS-11446: Keep blank lines in annotation
2 parents 169b862 + 476f5a8 commit 4a2913b

File tree

20 files changed

+65
-42
lines changed

20 files changed

+65
-42
lines changed

lib/MusicBrainz/Server/Data/Utils.pm

+10-4
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,16 @@ sub trim_multiline_text {
367367

368368
$t = NFC($t);
369369
$t = remove_invalid_characters($t);
370-
# Not trimming starting spaces to avoid breaking
371-
# either list formatting in Wikitext
372-
# or block in Markdown.
373-
$t =~ s/\s+$//gm;
370+
371+
# Trimming each line to remove trailing spaces (or similar)
372+
# - Not trimming starting spaces to avoid breaking
373+
# either list formatting in Wikitext
374+
# or block in Markdown.
375+
# - Splitting on \n so that \s doesn’t match any \n
376+
$t = join ("\n", map { $_ =~ s/\s+$//r } (split "\n", $t));
377+
378+
# Merge consecutive blank lines together
379+
$t =~ s/\n+(\n\n)/$1/g;
374380

375381
return $t;
376382
}

lib/MusicBrainz/Server/Edit/Area/Create.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ sub build_display_data
6969
type => $type ? to_json_object($loaded->{AreaType}{$type}) : undef,
7070
begin_date => to_json_object(PartialDate->new($self->data->{begin_date})),
7171
end_date => to_json_object(PartialDate->new($self->data->{end_date})),
72-
area => to_json_object(
73-
($self->entity_id && $loaded->{Area}{ $self->entity_id }) ||
72+
area => to_json_object((defined($self->entity_id) &&
73+
$loaded->{Area}{ $self->entity_id }) ||
7474
Area->new( name => $self->data->{name} )
7575
),
7676
ended => boolean_to_json($self->data->{ended}),

lib/MusicBrainz/Server/Edit/Artist/Create.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ sub build_display_data
8181

8282
my $type = $self->data->{type_id};
8383
my $gender = $self->data->{gender_id};
84-
my $artist = to_json_object(
85-
($self->entity_id && $loaded->{Artist}{ $self->entity_id }) ||
86-
Artist->new( name => $self->data->{name} )
84+
my $artist = to_json_object((defined($self->entity_id) &&
85+
$loaded->{Artist}{ $self->entity_id }) ||
86+
Artist->new( name => $self->data->{name} )
8787
);
8888

8989
return {

lib/MusicBrainz/Server/Edit/Event/Create.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ sub build_display_data
5252
my ($self, $loaded) = @_;
5353

5454
my $type = $self->data->{type_id};
55-
my $event = to_json_object(
56-
($self->entity_id && $loaded->{Event}{ $self->entity_id }) ||
57-
Event->new( name => $self->data->{name} )
55+
my $event = to_json_object((defined($self->entity_id) &&
56+
$loaded->{Event}{ $self->entity_id }) ||
57+
Event->new( name => $self->data->{name} )
5858
);
5959

6060
return {

lib/MusicBrainz/Server/Edit/Instrument/Create.pm

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ sub build_display_data {
4747
return {
4848
( map { $_ => $_ ? $self->data->{$_} : '' } qw( name ) ),
4949
type => $type ? to_json_object($loaded->{InstrumentType}{$type}) : undef,
50-
instrument => ($self->entity_id && to_json_object(
51-
$loaded->{Instrument}{ $self->entity_id } ||
52-
Instrument->new( id => $self->entity_id, name => $self->data->{name} )
53-
)),
50+
instrument => to_json_object((defined($self->entity_id) &&
51+
$loaded->{Instrument}{ $self->entity_id }) ||
52+
Instrument->new( name => $self->data->{name} )
53+
),
5454
comment => $self->data->{comment},
5555
description => $self->data->{description},
5656
};

lib/MusicBrainz/Server/Edit/Place/Create.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ sub build_display_data
6262
type => $type ? to_json_object($loaded->{PlaceType}{$type}) : undef,
6363
begin_date => to_json_object(PartialDate->new($self->data->{begin_date})),
6464
end_date => to_json_object(PartialDate->new($self->data->{end_date})),
65-
place => ($self->entity_id && to_json_object(
65+
place => to_json_object((defined($self->entity_id) &&
6666
$loaded->{Place}{ $self->entity_id }) ||
6767
Place->new( name => $self->data->{name} )
6868
),

lib/MusicBrainz/Server/Edit/Recording/Create.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ sub build_display_data
5858
comment => $self->data->{comment},
5959
length => $self->data->{length},
6060
video => boolean_to_json($self->data->{video}),
61-
recording => to_json_object(
62-
$loaded->{Recording}{ $self->entity_id } ||
61+
recording => to_json_object((defined($self->entity_id) &&
62+
$loaded->{Recording}{ $self->entity_id }) ||
6363
Recording->new( name => $self->data->{name} )
6464
),
6565
};

lib/MusicBrainz/Server/Edit/Series/Create.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ sub build_display_data {
5656
return {
5757
name => $name,
5858
comment => $comment,
59-
series => to_json_object(
60-
$loaded->{Series}{$self->entity_id} //
59+
series => to_json_object((defined($self->entity_id) &&
60+
$loaded->{Series}{$self->entity_id}) ||
6161
Series->new(
6262
name => $name,
6363
comment => $comment,
6464
type_id => $type_id,
6565
ordering_type_id => $ordering_type_id,
6666
),
67-
),
67+
),
6868
type => to_json_object($loaded->{SeriesType}{$type_id}),
6969
ordering_type => to_json_object($loaded->{SeriesOrderingType}{$ordering_type_id}),
7070
};

lib/MusicBrainz/Server/Edit/Work/Create.pm

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ sub build_display_data
6060
comment => $data->{comment} // '',
6161
type => $data->{type_id} && to_json_object($loaded->{WorkType}{ $data->{type_id} }),
6262
iswc => $data->{iswc} // '',
63-
work => to_json_object($loaded->{Work}{ $self->entity_id } || Work->new( name => $data->{name} )),
63+
work => to_json_object((defined($self->entity_id) &&
64+
$loaded->{Work}{ $self->entity_id }) ||
65+
Work->new( name => $self->data->{name} )
66+
),
6467
($data->{attributes} && @{ $data->{attributes} } ?
6568
( attributes => { $self->grouped_attributes_by_type($data->{attributes}, 1) } ) : ()
6669
),
@@ -71,7 +74,7 @@ sub build_display_data
7174
if ($language->iso_code_3 eq "zxx") {
7275
$language->name(l("[No lyrics]"));
7376
}
74-
$display->{language} = $language;
77+
$display->{language} = to_json_object($language);
7578
}
7679

7780
if (defined $data->{languages}) {

lib/MusicBrainz/Server/Entity/AutoEditorElection.pm

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use namespace::autoclean;
55
use MusicBrainz::Server::Entity::Types;
66
use MusicBrainz::Server::Constants qw( :election_status );
77
use MusicBrainz::Server::Data::Utils qw( boolean_to_json datetime_to_iso8601 );
8+
use MusicBrainz::Server::Entity::Util::JSON qw( to_json_array );
89
use MusicBrainz::Server::Types qw( DateTime AutoEditorElectionStatus );
910
use MusicBrainz::Server::Translation qw( N_lp );
1011

@@ -191,7 +192,7 @@ around TO_JSON => sub {
191192
seconder_2 => editor_to_json($self->seconder_2),
192193
status_name => $self->status_name,
193194
status_name_short => $self->status_name_short,
194-
votes => $self->votes,
195+
votes => to_json_array($self->votes),
195196
yes_votes => $self->yes_votes,
196197
};
197198
};

lib/MusicBrainz/Server/Entity/ExampleRelationship.pm

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package MusicBrainz::Server::Entity::ExampleRelationship;
22
use Moose;
33

4+
use MusicBrainz::Server::Data::Utils qw( boolean_to_json );
5+
use MusicBrainz::Server::Entity::Util::JSON qw( to_json_object );
6+
47
has name => (
58
isa => 'Str',
69
required => 1,
@@ -18,4 +21,14 @@ has relationship => (
1821
required => 1
1922
);
2023

24+
sub TO_JSON {
25+
my ($self) = @_;
26+
27+
return {
28+
name => $self->name,
29+
published => boolean_to_json($self->published),
30+
relationship => to_json_object($self->relationship),
31+
};
32+
}
33+
2134
1;

lib/MusicBrainz/Server/Entity/LinkType.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ around TO_JSON => sub {
144144
$json->{cardinality1} = $self->entity1_cardinality;
145145
$json->{deprecated} = boolean_to_json($self->is_deprecated);
146146
$json->{documentation} = $self->documentation;
147-
$json->{examples} = $self->examples;
147+
$json->{examples} = to_json_array($self->examples);
148148
$json->{has_dates} = boolean_to_json($self->has_dates);
149149
$json->{id} = $self->id;
150150
$json->{root_id} = $self->root_id;

t/lib/t/MusicBrainz/Server/Controller/Artist/AddAnnotation.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $mech->submit_form( with_fields => { username => 'new_editor', password => 'pass
2222
$mech->get_ok('/artist/745c079d-374e-4436-9448-da92dedef3ce/edit_annotation');
2323
$mech->submit_form(
2424
with_fields => {
25-
'edit-annotation.text' => " * Test annotation\x{0007} for an artist \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
25+
'edit-annotation.text' => " * Test annotation\x{0007} for an artist \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
2626
'edit-annotation.changelog' => 'Changelog here',
2727
});
2828

@@ -35,7 +35,7 @@ is_deeply($edit->data, {
3535
id => 3,
3636
name => 'Test Artist',
3737
},
38-
text => " * Test annotation for an artist\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
38+
text => " * Test annotation for an artist\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
3939
changelog => 'Changelog here',
4040
editor_id => 1
4141
});

t/lib/t/MusicBrainz/Server/Controller/Label/AddAnnotation.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $mech->submit_form( with_fields => { username => 'new_editor', password => 'pass
1919
$mech->get_ok('/label/4b4ccf60-658e-11de-8a39-0800200c9a66/edit_annotation');
2020
$mech->submit_form(
2121
with_fields => {
22-
'edit-annotation.text' => " * Test annotation\x{0007} for a label \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
22+
'edit-annotation.text' => " * Test annotation\x{0007} for a label \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
2323
'edit-annotation.changelog' => 'Changelog here',
2424
});
2525

@@ -32,7 +32,7 @@ is_deeply($edit->data, {
3232
id => 3,
3333
name => 'Another Label'
3434
},
35-
text => " * Test annotation for a label\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
35+
text => " * Test annotation for a label\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
3636
changelog => 'Changelog here',
3737
editor_id => 1
3838
});

t/lib/t/MusicBrainz/Server/Controller/Recording/AddAnnotation.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $mech->submit_form( with_fields => { username => 'new_editor', password => 'pass
1919
$mech->get_ok('/recording/123c079d-374e-4436-9448-da92dedef3ce/edit_annotation');
2020
$mech->submit_form(
2121
with_fields => {
22-
'edit-annotation.text' => " * Test annotation\x{0007} for a recording \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
22+
'edit-annotation.text' => " * Test annotation\x{0007} for a recording \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
2323
'edit-annotation.changelog' => 'Changelog here',
2424
});
2525

@@ -30,7 +30,7 @@ is_deeply($edit->data, {
3030
id => 1,
3131
name => 'Dancing Queen'
3232
},
33-
text => " * Test annotation for a recording\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
33+
text => " * Test annotation for a recording\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
3434
changelog => 'Changelog here',
3535
editor_id => 1
3636
});

t/lib/t/MusicBrainz/Server/Controller/Release/AddAnnotation.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $mech->submit_form( with_fields => { username => 'new_editor', password => 'pass
1919
$mech->get_ok('/release/f205627f-b70a-409d-adbe-66289b614e80/edit_annotation');
2020
$mech->submit_form(
2121
with_fields => {
22-
'edit-annotation.text' => " * Test annotation\x{0007} for a release \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
22+
'edit-annotation.text' => " * Test annotation\x{0007} for a release \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
2323
'edit-annotation.changelog' => 'Changelog here',
2424
});
2525

@@ -30,7 +30,7 @@ is_deeply($edit->data, {
3030
id => 2,
3131
name => 'Aerial'
3232
},
33-
text => " * Test annotation for a release\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
33+
text => " * Test annotation for a release\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
3434
changelog => 'Changelog here',
3535
editor_id => 1
3636
});

t/lib/t/MusicBrainz/Server/Controller/ReleaseGroup/AddAnnotation.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $mech->submit_form( with_fields => { username => 'new_editor', password => 'pass
1919
$mech->get_ok('/release-group/234c079d-374e-4436-9448-da92dedef3ce/edit_annotation');
2020
$mech->submit_form(
2121
with_fields => {
22-
'edit-annotation.text' => " * Test annotation\x{0007} for a release group \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
22+
'edit-annotation.text' => " * Test annotation\x{0007} for a release group \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
2323
'edit-annotation.changelog' => 'Changelog here',
2424
});
2525

@@ -30,7 +30,7 @@ is_deeply($edit->data, {
3030
id => 1,
3131
name => 'Arrival'
3232
},
33-
text => " * Test annotation for a release group\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
33+
text => " * Test annotation for a release group\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
3434
changelog => 'Changelog here',
3535
editor_id => 1
3636
});

t/lib/t/MusicBrainz/Server/Controller/Series/AddAnnotation.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test all => sub {
2020
$mech->get_ok('/series/a8749d0c-4a5a-4403-97c5-f6cd018f8e6d/edit_annotation');
2121
$mech->submit_form(
2222
with_fields => {
23-
'edit-annotation.text' => " * Test annotation\x{0007} for a series \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
23+
'edit-annotation.text' => " * Test annotation\x{0007} for a series \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
2424
'edit-annotation.changelog' => 'And a changelog',
2525
});
2626

@@ -35,7 +35,7 @@ test all => sub {
3535
id => 1,
3636
name => 'Test Recording Series'
3737
},
38-
text => " * Test annotation for a series\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
38+
text => " * Test annotation for a series\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
3939
changelog => 'And a changelog',
4040
editor_id => 1
4141
});

t/lib/t/MusicBrainz/Server/Controller/WS/js/Edit.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ test 'previewing/creating/editing a release group and release' => sub {
660660
my $annotation_edits = [ {
661661
edit_type => $EDIT_RELEASE_ADD_ANNOTATION,
662662
entity => $release_id,
663-
text => " * Test annotation\x{0007} in release editor \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
663+
text => " * Test annotation\x{0007} in release editor \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
664664
} ];
665665

666666
@edits = capture_edits {
@@ -674,7 +674,7 @@ test 'previewing/creating/editing a release group and release' => sub {
674674
cmp_deeply($edits[0]->data, {
675675
editor_id => 1,
676676
entity => { id => $release_id, name => 'Vision Creation Newsun' },
677-
text => " * Test annotation in release editor\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
677+
text => " * Test annotation in release editor\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
678678
});
679679
};
680680

t/lib/t/MusicBrainz/Server/Controller/Work/AddAnnotation.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $mech->submit_form( with_fields => { username => 'new_editor', password => 'pass
1919
$mech->get_ok("/work/745c079d-374e-4436-9448-da92dedef3ce/edit_annotation");
2020
$mech->submit_form(
2121
with_fields => {
22-
'edit-annotation.text' => " * Test annotation\x{0007} for a work \r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
22+
'edit-annotation.text' => " * Test annotation\x{0007} for a work \r\n\r\n\t\x{00A0}\r\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets \t\t",
2323
'edit-annotation.changelog' => 'Changelog here',
2424
}
2525
);
@@ -33,7 +33,7 @@ is_deeply(
3333
id => 1,
3434
name => 'Dancing Queen'
3535
},
36-
text => " * Test annotation for a work\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
36+
text => " * Test annotation for a work\n\n * This anno\x{200B}tation has\ttwo bul\x{00AD}lets",
3737
changelog => 'Changelog here',
3838
editor_id => 1
3939
}

0 commit comments

Comments
 (0)