
theory at bricolage
Mar 6, 2009, 4:54 PM
Post #1 of 1
(363 views)
Permalink
|
|
[8462] Fixed the issue with the casing of media file names.
|
|
Revision: 8462 Author: theory Date: 2009-03-06 16:54:42 -0800 (Fri, 06 Mar 2009) ViewCVS: http://viewsvn.bricolage.cc/?rev=8462&view=rev Log Message: ----------- Fixed the issue with the casing of media file names. We were not being consistent in how we constructed the file name part of the URI, and now we are: It is now always passed to `$oc->get_filename()` and it is always URI escaped. Modified Paths: -------------- bricolage/trunk/lib/Bric/Biz/Asset/Business/Media.pm bricolage/trunk/lib/Bric/Biz/OutputChannel.pm bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm Modified: bricolage/trunk/lib/Bric/Biz/Asset/Business/Media.pm =================================================================== --- bricolage/trunk/lib/Bric/Biz/Asset/Business/Media.pm 2009-03-07 00:37:47 UTC (rev 8461) +++ bricolage/trunk/lib/Bric/Biz/Asset/Business/Media.pm 2009-03-07 00:54:42 UTC (rev 8462) @@ -1218,8 +1218,10 @@ my ($uri, $update_uri); if ($self->get_file_name) { $update_uri = 1; - $uri = Bric::Util::Trans::FS->cat_uri - ( $self->_construct_uri($cat, $oc), $oc->get_filename($self)); + $uri = Bric::Util::Trans::FS->cat_uri( + $self->_construct_uri($cat, $oc), + escape_uri($oc->get_filename($self)) + ); } # If we've changed the category we need to repreview it if on autopreview @@ -1246,8 +1248,10 @@ my $oc = Bric::Biz::OutputChannel->lookup({ id => $id }); my $cat = $self->get_category_object; $update_uri = 1; - $uri = Bric::Util::Trans::FS->cat_uri - ( $self->_construct_uri($cat, $oc), $oc->get_filename($self)); + $uri = Bric::Util::Trans::FS->cat_uri( + $self->_construct_uri($cat, $oc), + escape_uri($oc->get_filename($self)) + ); } $self->_set([qw(primary_oc_id uri _update_uri)] => [ $id, $uri, $update_uri]); @@ -1312,7 +1316,6 @@ my $cover_date = db_date(shift); my ($old, $cat, $cat_id) = $self->_get(qw(cover_date _category_obj category__id)); - my $fn = $self->get_file_name; return $self unless (defined $cover_date && not defined $old) || (not defined $cover_date && defined $old) @@ -1323,13 +1326,15 @@ $self->_set(['cover_date'] => [$cover_date]); my ($uri, $update_uri); - if (defined $fn) { + if (defined $self->get_file_name) { $update_uri = 1; $cat ||= Bric::Biz::Category->lookup({ id => $cat_id }); my $oc = $self->get_primary_oc; if ($cat and $oc) { - $uri = Bric::Util::Trans::FS->cat_uri - ($self->_construct_uri($cat, $oc), $fn); + $uri = Bric::Util::Trans::FS->cat_uri( + $self->_construct_uri($cat, $oc), + escape_uri($oc->get_filename($self)) + ); } } Modified: bricolage/trunk/lib/Bric/Biz/OutputChannel.pm =================================================================== --- bricolage/trunk/lib/Bric/Biz/OutputChannel.pm 2009-03-07 00:37:47 UTC (rev 8461) +++ bricolage/trunk/lib/Bric/Biz/OutputChannel.pm 2009-03-07 00:54:42 UTC (rev 8462) @@ -1135,8 +1135,9 @@ } # Return the filename with the proper case. - return $case eq MIXEDCASE ? $fn : - $case eq LOWERCASE ? lc $fn : uc $fn; + return $case eq MIXEDCASE ? $fn + : $case eq LOWERCASE ? lc $fn + : uc $fn; } =item $oc = $oc->set_file_ext($file_ext) Modified: bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm =================================================================== --- bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm 2009-03-07 00:37:47 UTC (rev 8461) +++ bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm 2009-03-07 00:54:42 UTC (rev 8462) @@ -961,7 +961,7 @@ 'asset_grp_ids'); } -sub test_upload_before_save : Test(9) { +sub test_upload_before_save : Test(26) { my $self = shift; my $class = $self->class; @@ -1005,6 +1005,46 @@ like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; like $media->get_uri, qr{/some%20file[.]png$}, 'But the URI should be lowercased and URI escaped'; + + # Change the cover date. + ok $media->set_cover_date('1968-12-19 19:42:00'), 'Set the cover date'; + is $media->get_file_name, 'Some file.png', 'The file name should still be uppercase'; + like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; + like $media->get_uri, qr{/some%20file[.]png$}, + 'And the URI should still be lowercased and URI escaped'; + + # Change the category. + ok my $cat = Bric::Biz::Category->new({ + name => 'Testing', + site_id => 100, + parent_id => 1, + directory => 'testing', + }), 'Create a new category'; + ok $cat->save, 'Save the new category'; + $self->add_del_ids($cat->get_id, 'category'); + + ok $media->set_category__id($cat->get_id), 'Change the category ID'; + is $media->get_file_name, 'Some file.png', 'The file name should still be uppercase'; + like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; + like $media->get_uri, qr{/some%20file[.]png$}, + 'And the URI should still be lowercased and URI escaped'; + + # Change the primary output channel. + ok my $oc2 = Bric::Biz::OutputChannel->new({ + name => 'Foo', + site_id => 100, + uri_case => LOWERCASE, + }), 'Create a new OC'; + ok $oc2->save, 'Save the new category'; + $self->add_del_ids($oc2->get_id, 'output_channel'); + + ok $media->set_primary_oc_id($oc2->get_id), 'Change the primary OC'; + is $media->get_file_name, 'Some file.png', 'The file name should still be uppercase'; + like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; + like $media->get_uri, qr{/some%20file[.]png$}, + 'And the URI should still be lowercased and URI escaped'; + like $media->get_uri($oc2), qr{/some%20file[.]png$}, + 'And the URI should be lowercased when the OC is passed to uri()'; } sub cleanup_oc : Test(teardown) {
|