Skip to content

Commit

Permalink
MBS-12721: Normalize 45cat.com/45worlds.com links to HTTPS (#2748)
Browse files Browse the repository at this point in the history
These now redirect to HTTPS.

Supporting both for the 45worlds sidebar_name construction
since there's probably going to be HTTP links for a while anyway,
but making sure we display them all as HTTPS with href_url.
  • Loading branch information
reosarevok authored Jan 26, 2023
1 parent 2d9f6e4 commit 2fec0d5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
4 changes: 4 additions & 0 deletions lib/MusicBrainz/Server/Entity/URL/45cat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use Moose;
extends 'MusicBrainz::Server::Entity::URL';
with 'MusicBrainz::Server::Entity::URL::Sidebar';

override href_url => sub {
shift->url->as_string =~ s{^http:}{https:}r;
};

sub sidebar_name { '45cat' }

__PACKAGE__->meta->make_immutable;
Expand Down
8 changes: 6 additions & 2 deletions lib/MusicBrainz/Server/Entity/URL/45worlds.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ use Moose;
extends 'MusicBrainz::Server::Entity::URL';
with 'MusicBrainz::Server::Entity::URL::Sidebar';

override href_url => sub {
shift->url->as_string =~ s{^http:}{https:}r;
};

sub sidebar_name {
my $self = shift;

if ($self->url =~ m{^(?:http://www.45worlds.com/([a-z0-9]+)/(?:artist|label)/[^/?&#]+)$}i) {
if ($self->url =~ m{^(?:https?://www.45worlds.com/([a-z0-9]+)/(?:artist|label)/[^/?&#]+)$}i) {
return '45worlds ' . $1;
}
elsif ($self->url =~ m{^(?:http://www.45worlds.com/classical/(composer|conductor|orchestra|soloist)/[^/?&#]+)$}i) {
elsif ($self->url =~ m{^(?:https?://www.45worlds.com/classical/(composer|conductor|orchestra|soloist)/[^/?&#]+)$}i) {
return '45worlds classical (' . $1 . ')';
}
else {
Expand Down
8 changes: 4 additions & 4 deletions root/static/scripts/edit/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ const CLEANUPS: CleanupEntries = {
// $FlowIssue[incompatible-type]: Array<mixed>
restrict: [LINK_TYPES.otherdatabases],
clean: function (url) {
return url.replace(/^(?:https?:\/\/)?(?:www\.)?45cat\.com\/([a-z]+\/[^\/?&#]+)(?:[\/?&#].*)?$/, 'http://www.45cat.com/$1');
return url.replace(/^(?:https?:\/\/)?(?:www\.)?45cat\.com\/([a-z]+\/[^\/?&#]+)(?:[\/?&#].*)?$/, 'https://www.45cat.com/$1');
},
validate: function (url, id) {
const m = /^http:\/\/www\.45cat\.com\/([a-z]+)\/[^\/?&#]+$/.exec(url);
const m = /^https:\/\/www\.45cat\.com\/([a-z]+)\/[^\/?&#]+$/.exec(url);
if (m) {
const prefix = m[1];
switch (id) {
Expand Down Expand Up @@ -486,10 +486,10 @@ const CLEANUPS: CleanupEntries = {
match: [new RegExp('^(https?://)?(www\\.)?45worlds\\.com/', 'i')],
restrict: [LINK_TYPES.otherdatabases],
clean: function (url) {
return url.replace(/^(?:https?:\/\/)?(?:www\.)?45worlds\.com\/([0-9a-z]+\/[a-z]+\/[^\/?&#]+)(?:[\/?&#].*)?$/, 'http://www.45worlds.com/$1');
return url.replace(/^(?:https?:\/\/)?(?:www\.)?45worlds\.com\/([0-9a-z]+\/[a-z]+\/[^\/?&#]+)(?:[\/?&#].*)?$/, 'https://www.45worlds.com/$1');
},
validate: function (url, id) {
const m = /^http:\/\/www\.45worlds\.com\/([0-9a-z]+)\/([a-z]+)\/[^\/?&#]+$/.exec(url);
const m = /^https:\/\/www\.45worlds\.com\/([0-9a-z]+)\/([a-z]+)\/[^\/?&#]+$/.exec(url);
if (m) {
const prefix = m[2];
switch (id) {
Expand Down
28 changes: 14 additions & 14 deletions root/static/scripts/tests/Control/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,25 @@ const testData = [
input_url: 'https://www.45cat.com/artist/edwin-starr',
input_entity_type: 'artist',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45cat.com/artist/edwin-starr',
expected_clean_url: 'https://www.45cat.com/artist/edwin-starr',
only_valid_entity_types: ['artist'],
},
{
input_url: 'www.45cat.com/label/eastwest/all',
input_entity_type: 'label',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45cat.com/label/eastwest',
expected_clean_url: 'https://www.45cat.com/label/eastwest',
only_valid_entity_types: ['label'],
},
{
input_url: 'http://45cat.com/record/vs1370&rc=365077#365077',
input_entity_type: 'release_group',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45cat.com/record/vs1370',
expected_clean_url: 'https://www.45cat.com/record/vs1370',
only_valid_entity_types: ['release_group'],
},
{
input_url: 'http://www.45cat.com/45_composer.php?tc=Floyd+Hunt',
input_url: 'https://www.45cat.com/45_composer.php?tc=Floyd+Hunt',
input_entity_type: 'artist',
expected_relationship_type: 'otherdatabases',
only_valid_entity_types: [],
Expand All @@ -162,70 +162,70 @@ const testData = [
input_url: 'http://www.45worlds.com/78rpm/artist/yehudi-menuhin',
input_entity_type: 'artist',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/78rpm/artist/yehudi-menuhin',
expected_clean_url: 'https://www.45worlds.com/78rpm/artist/yehudi-menuhin',
only_valid_entity_types: ['artist'],
},
{
input_url: 'https://45worlds.com/classical/artist/yehudi-menuhin',
input_entity_type: 'artist',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/classical/artist/yehudi-menuhin',
expected_clean_url: 'https://www.45worlds.com/classical/artist/yehudi-menuhin',
only_valid_entity_types: ['artist'],
},
{
input_url: 'www.45worlds.com/classical/soloist/yehudi-menuhin',
input_entity_type: 'artist',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/classical/soloist/yehudi-menuhin',
expected_clean_url: 'https://www.45worlds.com/classical/soloist/yehudi-menuhin',
only_valid_entity_types: ['artist'],
},
{
input_url: 'http://www.45worlds.com/live/listing/rumer-fawcetts-field-2012&rc=186697#186697',
input_entity_type: 'event',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/live/listing/rumer-fawcetts-field-2012',
expected_clean_url: 'https://www.45worlds.com/live/listing/rumer-fawcetts-field-2012',
only_valid_entity_types: ['event'],
},
{
input_url: 'http://www.45worlds.com/tape/label/parlophone/all',
input_entity_type: 'label',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/tape/label/parlophone',
expected_clean_url: 'https://www.45worlds.com/tape/label/parlophone',
only_valid_entity_types: ['label'],
},
{
input_url: 'http://www.45worlds.com/live/venue/stadium-high-school-stadium',
input_entity_type: 'place',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/live/venue/stadium-high-school-stadium',
expected_clean_url: 'https://www.45worlds.com/live/venue/stadium-high-school-stadium',
only_valid_entity_types: ['place'],
},
{
input_url: 'http://www.45worlds.com/vinyl/album/mfsl1100',
input_entity_type: 'release_group',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/vinyl/album/mfsl1100',
expected_clean_url: 'https://www.45worlds.com/vinyl/album/mfsl1100',
only_valid_entity_types: ['release_group'],
},
{
input_url: 'http://www.45worlds.com/12single/record/fu2t',
input_entity_type: 'release_group',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/12single/record/fu2t',
expected_clean_url: 'https://www.45worlds.com/12single/record/fu2t',
only_valid_entity_types: ['release_group'],
},
{
input_url: 'http://www.45worlds.com/cdsingle/cd/pwcd227',
input_entity_type: 'release_group',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/cdsingle/cd/pwcd227',
expected_clean_url: 'https://www.45worlds.com/cdsingle/cd/pwcd227',
only_valid_entity_types: ['release_group'],
},
{
input_url: 'http://www.45worlds.com/classical/music/asd264',
input_entity_type: 'release_group',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://www.45worlds.com/classical/music/asd264',
expected_clean_url: 'https://www.45worlds.com/classical/music/asd264',
only_valid_entity_types: ['release_group'],
},
// 7digital (zdigital)
Expand Down

0 comments on commit 2fec0d5

Please sign in to comment.