Skip to content

Commit 5730b74

Browse files
authored
Merge pull request #3702 from reosarevok/MBS-14231
MBS-14231: Block API POST of tags with commas
2 parents 0f335e0 + 6c513a5 commit 5730b74

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

lib/MusicBrainz/Server/Controller/WS/2/Tag.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ sub tag_submit : Private
112112
$self->_error($c, 'Unrecognized vote type: ' . $vote);
113113
}
114114
}
115+
# Block upvoting and downvoting tags with commas, which are not
116+
# properly supported by the UI. Still allow withdrawing tags
117+
# with commas to delete legacy tags.
118+
if ($name =~ /,/ && $vote ne 'withdraw') {
119+
$self->_error($c, 'The tag name cannot contain commas. To submit multiple tags, send multiple user-tag elements.');
120+
}
121+
115122
push @{ $submit->{$name} //= [] }, [$model, $vote, $entity->id];
116123
}
117124

t/lib/t/MusicBrainz/Server/Controller/WS/2/Authenticated.pm

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,78 @@ test 'Empty tag names are disallowed' => sub {
318318
is_xml_same($mech->content, $error_message);
319319
};
320320

321+
322+
test 'Tags with commas are disallowed' => sub {
323+
my $test = shift;
324+
my $c = $test->c;
325+
my $mech = $test->mech;
326+
327+
MusicBrainz::Server::Test->prepare_test_database($c, '+edit_recording');
328+
MusicBrainz::Server::Test->prepare_test_database($c, <<~'SQL');
329+
SELECT setval('tag_id_seq', (SELECT MAX(id) FROM tag));
330+
INSERT INTO editor (id, name, password, ha1)
331+
VALUES (1, 'new_editor', '{CLEARTEXT}password', 'e1dd8fee8ee728b0ddc8027d3a3db478')
332+
SQL
333+
334+
my $error_message = <<~'EOXML';
335+
<?xml version="1.0"?>
336+
<error>
337+
<text>The tag name cannot contain commas. To submit multiple tags, send multiple user-tag elements.</text>
338+
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
339+
</error>
340+
EOXML
341+
342+
$mech->default_header('Accept' => 'application/xml');
343+
$mech->credentials('localhost:80', 'musicbrainz.org', 'new_editor', 'password');
344+
345+
my $content = <<~'EOXML';
346+
<?xml version="1.0" encoding="UTF-8"?>
347+
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
348+
<recording-list>
349+
<recording id="581556f0-755f-11de-8a39-0800200c9a66">
350+
<user-tag-list>
351+
<user-tag><name>TAG_NAME</name></user-tag>
352+
</user-tag-list>
353+
</recording>
354+
</recording-list>
355+
</metadata>
356+
EOXML
357+
358+
$mech->request(xml_post('/ws/2/tag?client=post.t-0.0.2', $content =~ s/TAG_NAME/have, a comma/r));
359+
is($mech->status, HTTP_BAD_REQUEST, 'Bad request error since commas in legacy tags are disallowed');
360+
is_xml_same($mech->content, $error_message);
361+
362+
$content = <<~'EOXML';
363+
<?xml version="1.0" encoding="UTF-8"?>
364+
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
365+
<recording-list>
366+
<recording id="581556f0-755f-11de-8a39-0800200c9a66">
367+
<user-tag-list>
368+
<user-tag vote="upvote"><name>TAG_NAME</name></user-tag>
369+
</user-tag-list>
370+
</recording>
371+
</recording-list>
372+
</metadata>
373+
EOXML
374+
375+
$mech->request(xml_post('/ws/2/tag?client=post.t-0.0.2', $content =~ s/TAG_NAME/have, a comma/r));
376+
is($mech->status, HTTP_BAD_REQUEST, 'Bad request error since commas in upvote tags are disallowed');
377+
is_xml_same($mech->content, $error_message);
378+
379+
$content = <<~'EOXML';
380+
<?xml version="1.0" encoding="UTF-8"?>
381+
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
382+
<recording-list>
383+
<recording id="581556f0-755f-11de-8a39-0800200c9a66">
384+
<user-tag-list>
385+
<user-tag vote="withdraw"><name>TAG_NAME</name></user-tag>
386+
</user-tag-list>
387+
</recording>
388+
</recording-list>
389+
</metadata>
390+
EOXML
391+
392+
$mech->request(xml_post('/ws/2/tag?client=post.t-0.0.2', $content =~ s/TAG_NAME/have, a comma/r));
393+
is($mech->status, HTTP_OK, 'No error is returned since commas in withdraw tags are allowed');
394+
};
321395
1;

0 commit comments

Comments
 (0)