From 13eb87ffe57d8f171e83b7decf4864f434bbb678 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 21 Nov 2008 23:07:05 +0000 Subject: [PATCH] forward porting fix for non-unique separator strings, ~~~, #8543 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset.pm | 17 +++++++++++++++++ lib/WebGUI/Asset/Event.pm | 8 ++++---- lib/WebGUI/Asset/File/GalleryFile.pm | 4 ++-- lib/WebGUI/Asset/Post/Thread.pm | 4 ++-- lib/WebGUI/Asset/Shortcut.pm | 4 ++-- lib/WebGUI/Asset/Sku.pm | 4 ++-- lib/WebGUI/Asset/Wobject.pm | 4 ++-- lib/WebGUI/Asset/Wobject/Calendar.pm | 4 ++-- lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 4 ++-- lib/WebGUI/Asset/Wobject/HttpProxy.pm | 4 ++-- lib/WebGUI/Asset/Wobject/Layout.pm | 12 ++++++------ t/Asset/Asset.t | 11 ++++++++++- 13 files changed, 54 insertions(+), 27 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d9e71acc2..1d8c82a19 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -46,6 +46,7 @@ - fixed #9132: usage error in Hover Help - fixed #4181: hoover help for 'encrypt login' is wrong - fixed #4186: search results (macro not expanded in the synopsis field) + - fixed #4191: Using 3 consecutive tildes in a Post title makes a bad URL/Pos 7.6.3 - improved performance of file uploads diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 2a14b4fcc..45dcd25ce 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1244,6 +1244,23 @@ sub getRoot { } +#------------------------------------------------------------------- + +=head2 getSeparator + +Returns a very unique string that can be used for splitting head and body apart +from the style template. Made into a method in case it ever has to be changed +again. + +=cut + +sub getSeparator { + my $self = shift; + my $padCharacter = shift || '~'; + my $pad = $padCharacter x 3; + return $pad.$self->getId.$pad +} + #------------------------------------------------------------------- =head2 getTempspace ( session ) diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 2a875a533..b3d7ed07d 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -2422,8 +2422,8 @@ ENDJS ### Show the processed template $session->http->sendHeader; - my $style = $session->style->process("~~~",$self->getParent->get("styleTemplateId")); - my ($head, $foot) = split("~~~",$style); + my $style = $session->style->process($self->getSeparator,$self->getParent->get("styleTemplateId")); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); $self->session->output->print($self->processTemplate($var, undef, $template)); $self->session->output->print($foot, 1); @@ -2460,8 +2460,8 @@ sub www_view { $self->session->http->setCacheControl($self->get("visitorCacheTimeout")) if ($self->session->user->isVisitor); $self->session->http->sendHeader; $self->prepareView; - my $style = $self->getParent->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $self->getParent->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head,1); $self->session->output->print($self->view); $self->session->output->print($foot,1); diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index f5d7608d1..8fb6621f1 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -1070,8 +1070,8 @@ sub www_view { $self->session->http->setLastModified($self->getContentLastModified); $self->session->http->sendHeader; $self->prepareView; - my $style = $self->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $self->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); $self->session->output->print($self->view); $self->session->output->print($foot, 1); diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 27d5a3a6d..7d399e93b 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -1175,8 +1175,8 @@ sub www_view { $self->session->http->setCacheControl($self->get("visitorCacheTimeout")) if ($self->session->user->isVisitor); $self->session->http->sendHeader; $self->prepareView; - my $style = $self->getParent->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $self->getParent->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head,1); $self->session->output->print($self->view($currentPost)); $self->session->output->print($foot,1); diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index ec21a452d..c07c58756 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -973,8 +973,8 @@ sub www_view { if ($shortcut->isa('WebGUI::Asset::Wobject')) { $self->session->http->setLastModified($self->getContentLastModified); $self->session->http->sendHeader; - my $style = $shortcut->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $shortcut->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); $self->session->output->print($self->view); $self->session->output->print($foot, 1); diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index 8ae6b3bdf..9b01d9afe 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -514,8 +514,8 @@ sub www_view { $self->session->http->setLastModified($self->getContentLastModified); $self->session->http->sendHeader; $self->prepareView; - my $style = $self->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $self->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); $self->session->output->print($self->view); $self->session->output->print($foot, 1); diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index bbe0231a6..0570f8aa4 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -548,8 +548,8 @@ sub www_view { }); } $self->prepareView; - my $style = $self->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $self->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); $self->session->output->print($self->view); $self->session->output->print($foot, 1); diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index 52ed87378..0631eed18 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -2087,8 +2087,8 @@ sub www_search { # This is very bad! It should be $self->processStyle or whatnot. $self->session->http->sendHeader; my $template = WebGUI::Asset::Template->new($self->session,$self->get("templateIdSearch")); - my $style = $self->session->style->process("~~~",$self->get("styleTemplateId")); - my ($head, $foot) = split("~~~",$style); + my $style = $self->session->style->process($self->getSeparator,$self->get("styleTemplateId")); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); $self->session->output->print($self->processTemplate($var, undef, $template)); $self->session->output->print($foot, 1); diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index f518da632..1402968bd 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -763,8 +763,8 @@ sub sendChunkedContent { $self->session->http->setLastModified($self->getContentLastModified); $self->session->http->sendHeader; - my $style = $self->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $self->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); $self->session->output->print( $callback->() ); $self->session->output->print($foot, 1); diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index df1287f07..b4a98d936 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -439,8 +439,8 @@ sub www_view { return $output; } else { $self->session->http->sendHeader; - my $style = $self->processStyle("~~~"); - my ($head, $foot) = split("~~~",$style); + my $style = $self->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head); $self->session->output->print($output, 1); # Do not process macros $self->session->output->print($foot); diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index 11fe71702..8581d77f7 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -196,14 +196,14 @@ sub prepareView { push(@{$vars{"position1_loop"}},{ id=>$child->getId, isUncommitted=> $child->get('status') eq 'pending', - content=>"~~~".$child->getId."~~~~~" + content=>$self->getSeparator.$child->getId.$self->getSeparator('!'), }); } else { $placeHolder{$child->getId} = $child; push(@{$vars{"position".$i."_loop"}},{ id=>$child->getId, isUncommitted=>$child->get('status') eq 'pending', - content=>"~~~".$child->getId."~~~~~" + content=>$self->getSeparator.$child->getId.$self->getSeparator('!'), }); } } @@ -226,13 +226,13 @@ sub prepareView { if($self->getValue("assetOrder") eq "asc"){ push(@{$vars{"position1_loop"}},{ id=>$child->getId, - content=>"~~~".$child->getId."~~~~~" + content=>$self->getSeparator.$child->getId.$self->getSeparator('!'), }); } else { unshift(@{$vars{"position1_loop"}},{ id=>$child->getId, - content=>"~~~".$child->getId."~~~~~" + content=>$self->getSeparator.$child->getId.$self->getSeparator('!'), }); } } @@ -272,10 +272,10 @@ sub view { } my $showPerformance = $self->session->errorHandler->canShowPerformanceIndicators(); my $out = $self->processTemplate($self->{_viewVars},undef,$self->{_viewTemplate}); - my @parts = split("~~~~~",$self->processTemplate($self->{_viewVars},undef,$self->{_viewTemplate})); + my @parts = split($self->getSeparator('!'),$self->processTemplate($self->{_viewVars},undef,$self->{_viewTemplate})); my $output = ""; foreach my $part (@parts) { - my ($outputPart, $assetId) = split("~~~",$part,2); + my ($outputPart, $assetId) = split($self->getSeparator,$part,2); if ($self->{_viewPrintOverride}) { $self->session->output->print($outputPart); } else { diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index b342ea458..9bb02119a 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -148,7 +148,7 @@ $canViewMaker->prepare( }, ); -plan tests => 100 +plan tests => 103 + scalar(@fixIdTests) + scalar(@fixTitleTests) + 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle @@ -678,6 +678,15 @@ $session->setting->set('notFoundPage', $origNotFoundPage); ################################################################ is($rootAsset->get('isExportable'), 1, 'isExportable exists, defaults to 1'); +################################################################ +# +# getSeparator +# +################################################################ +is($rootAsset->getSeparator, '~~~PBasset000000000000001~~~', 'getSeparator, known assetId'); +is($rootAsset->getSeparator('!'), '!!!PBasset000000000000001!!!', 'getSeparator, given pad character'); +isnt($rootAsset->getSeparator, $mediaFolder->getSeparator, 'getSeparator: unique string'); + ################################################################ # # get