From 9d438f72668edfe34bbf4401ba79690822bd7a9e Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 22 Sep 2009 11:45:06 -0700 Subject: [PATCH] Fix bad URLs from happening when inheritUrlFromParent is used. Fixes bug #11011 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset.pm | 11 +++-------- t/Asset/Asset.t | 15 +++++++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 3295e6cc7..914ff1332 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -56,6 +56,7 @@ - fixed #10990: Survey: View Transposed Results not working - fixed #11009: Shipping address is lost after login - fixed #11010: Purchasing non-recurring subscription twice does not extend group membership + - fixed #11011: Inherit URL from parent can generate bad URLs 7.7.19 - fixed #10838: Forwarded forum post email to new CS adds reply to original thread diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index a667cd979..202fab508 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -681,12 +681,12 @@ sub fixUrl { $url =~ s/(.*)\..*/$1/; $url .= '/'.$self->getValue("menuTitle"); } - $url = $self->session->url->urlize($url); # if we're inheriting the URL from our parent, set that appropriately if($self->get('inheritUrlFromParent')) { $url = $self->fixUrlFromParent($url); } + $url = $self->session->url->urlize($url); # fix urls used by uploads and extras # and those beginning with http @@ -768,15 +768,10 @@ sub fixUrlFromParent { my @parts = split(m{/}, $url); # don't do anything unless we need to - if("/$url" ne $self->getParent->getUrl . '/' . $parts[-1]) { - $url = $self->getParent->getUrl . '/' . $parts[-1]; + if($url ne $self->getParent->get('url') . '/' . $parts[-1]) { + $url = $self->getParent->get('url') . '/' . $parts[-1]; } - ##Note we do not need to call fixUrl on the url argument. Here's the reasoning why. - ##If a URL has not been set to updated at the same time that inheritUrlFromParent is - ##called, then it has already been "fixed". - ##On the other hand, if it has, the sideEffect nature of this method guarantees that - ##the URL was "fixed" before it was called. return $url; } diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index 1695608cd..c3342dff9 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -153,7 +153,7 @@ $canViewMaker->prepare( }, ); -plan tests => 115 +plan tests => 116 + scalar(@fixIdTests) + scalar(@fixTitleTests) + 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle @@ -769,7 +769,7 @@ $properties2 = { my $iufpAsset2 = $iufpAsset->addChild($properties2, $properties2->{id}); $iufpAsset2->update( { inheritUrlFromParent => 1 } ); $iufpAsset2->commit; -is($iufpAsset2->getUrl, '/inheriturlfromparent01/inheriturlfromparent02', 'inheritUrlFromParent works'); +is($iufpAsset2->get('url'), 'inheriturlfromparent01/inheriturlfromparent02', 'inheritUrlFromParent works'); my $properties2a = { # '1234567890123456789012' @@ -782,15 +782,15 @@ my $properties2a = { my $iufpAsset2a = $iufpAsset->addChild($properties2a, $properties2a->{id}); $iufpAsset2a->commit; -is($iufpAsset2a->getUrl, '/inheriturlfromparent01/inheriturlfromparent2a', 'inheritUrlFromParent works when created with the property'); +is($iufpAsset2a->get('url'), 'inheriturlfromparent01/inheriturlfromparent2a', '... works when created with the property'); # works for setting, now try disabling. Should not change the URL. $iufpAsset2->update( { inheritUrlFromParent => 0 } ); $iufpAsset2->commit; -is($iufpAsset2->getUrl, '/inheriturlfromparent01/inheriturlfromparent02', 'setting inheritUrlFromParent to 0 works'); +is($iufpAsset2->get('url'), 'inheriturlfromparent01/inheriturlfromparent02', '... setting inheritUrlFromParent to 0 works'); # also make sure that it is actually disabled -is($iufpAsset2->get('inheritUrlFromParent'), 0, "disabling inheritUrlFromParent actually works"); +is($iufpAsset2->get('inheritUrlFromParent'), 0, "... disabling inheritUrlFromParent actually works"); # works for setting and disabling, now ensure it recurses @@ -807,7 +807,10 @@ $iufpAsset2->update( { inheritUrlFromParent => 1 } ); $iufpAsset2->commit; $iufpAsset3->update( { inheritUrlFromParent => 1 } ); $iufpAsset3->commit; -is($iufpAsset3->getUrl, '/inheriturlfromparent01/inheriturlfromparent02/inheriturlfromparent03', 'inheritUrlFromParent recurses properly'); +is($iufpAsset3->get('url'), 'inheriturlfromparent01/inheriturlfromparent02/inheriturlfromparent03', '... recurses properly'); + +$iufpAsset2->update({url => 'iufp2'}); +is($iufpAsset2->get('url'), 'inheriturlfromparent01/iufp2', '... update works propertly when iUFP is not passed'); ################################################################