From 90dec24634b9183ce3b8345f57758c4ca2e19a55 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 14 Feb 2011 17:49:47 -0800 Subject: [PATCH] Prevent an empty AssetProxy macro from causing an infinite loop. Fixes bug #12046. Thanks to Trex for the patch! --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Macro/AssetProxy.pm | 9 +++++++++ t/Macro/AssetProxy.t | 22 ++++++++++------------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 8b2c605e8..33d4f8784 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - fixed #12045: Job listing template, missing summary - fixed #12043: Collaboration Systems don't pull mail that fast! - fixed #12044: Spectre::Cron and non-integer time units + - fixed #12046: Empty AssetProxy creates infinite loop (Dale Trexel) 7.10.9 - fixed #12030: Calendar Feed Time Zone Issue diff --git a/lib/WebGUI/Macro/AssetProxy.pm b/lib/WebGUI/Macro/AssetProxy.pm index 0e7ef77ce..985538d91 100644 --- a/lib/WebGUI/Macro/AssetProxy.pm +++ b/lib/WebGUI/Macro/AssetProxy.pm @@ -42,6 +42,15 @@ Defaults to 'url'. But if you want to use an assetId as the first parameter, the #------------------------------------------------------------------- sub process { my ($session, $identifier, $type) = @_; + if (!$identifier) { + $session->errorHandler->warn('AssetProxy macro called without an asset to proxy. ' + . 'The macro was called through this url: '.$session->asset->get('url')); + if ($session->var->isAdminOn) { + my $i18n = WebGUI::International->new($session, 'Macro_AssetProxy'); + return $i18n->get('invalid url'); + } + return; + } my $t = ($session->errorHandler->canShowPerformanceIndicators()) ? [Time::HiRes::gettimeofday()] : undef; my $asset; if ($type eq 'assetId') { diff --git a/t/Macro/AssetProxy.t b/t/Macro/AssetProxy.t index 95f99752e..107ed7676 100644 --- a/t/Macro/AssetProxy.t +++ b/t/Macro/AssetProxy.t @@ -14,24 +14,22 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use HTML::TokeParser; +use WebGUI::Asset; use Test::More; # increment this value for each test you create my $session = WebGUI::Test->session; -my $numTests = 0; +plan tests => 2; -$numTests += 1; #For the use_ok +use WebGUI::Macro::AssetProxy; -plan tests => $numTests; +$session->asset(WebGUI::Asset->getDefault($session)); -my $macro = 'WebGUI::Macro::AssetProxy'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - -} +my $output; +$output = WebGUI::Macro::AssetProxy::process($session); +is $output, undef, 'calling AssetProxy with no identifier returns no error message in normal mode'; +$session->var->switchAdminOn; +$output = WebGUI::Macro::AssetProxy::process($session); +like $output, qr/Invalid Asset URL/, '..., adminOn, return error message';