diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9c0e19d25..b052ad782 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.5.18 + - fixed: User is logged out if a fatal error occurs - fixed: Collaboration system includes header link even with RSS turned off - fixed: edit branch doesn't show list style metadata fields properly - fixed: Product no longer shows "Continue Shopping" view when a different user adds the Product to their Cart. The issue was the Product cached itself when an item was added to the cart. Now it checks for if a cart asset exists for this session. diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 9baeeb043..6f0493091 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -66,15 +66,14 @@ sub handler { my $error = ""; my $matchUri = $request->uri; my $gateway = $config->get("gateway"); - $matchUri =~ s{^$gateway(.*)}{/$1}; + $matchUri =~ s{^$gateway}{/}; my $gotMatch = 0; - foreach my $handler (@{$config->get("urlHandlers")}) { + WEBGUI_FATAL: foreach my $handler (@{$config->get("urlHandlers")}) { my ($regex) = keys %{$handler}; if ($matchUri =~ m{$regex}i) { my $output = eval { WebGUI::Pluggable::run($handler->{$regex}, "handler", [$request, $server, $config]) }; if ($@) { $error = $@; - warn $@ if ($@ =~ "^fatal:"); last; } else { @@ -82,7 +81,7 @@ sub handler { if ($output ne Apache2::Const::DECLINED) { return $output; } - } + } } } return Apache2::Const::DECLINED if ($gotMatch); diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index f1a09ebd8..19a5820c3 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -19,7 +19,7 @@ use strict; use Log::Log4perl; use Apache2::RequestUtil; use JSON; -use HTML::Entities; +use HTML::Entities qw(encode_entities); =head1 NAME @@ -145,8 +145,9 @@ The message you wish to add to the log. sub debug { my $self = shift; my $message = shift; + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $self->getLogger->debug($message); - $self->{_debug_debug} .= $message."\n"; + $self->{_debug_debug} .= $message."\n"; } @@ -180,6 +181,7 @@ The message you wish to add to the log. sub error { my $self = shift; my $message = shift; + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $self->getLogger->error($message); $self->getLogger->debug("Stack trace for ERROR ".$message."\n".$self->getStackTrace()); $self->{_debug_error} .= $message."\n"; @@ -202,6 +204,7 @@ sub fatal { my $self = shift; my $message = shift; + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $self->session->http->setStatus("500","Server Error"); Apache2::RequestUtil->request->content_type('text/html') if ($self->session->request); $self->getLogger->fatal($message); @@ -228,7 +231,7 @@ sub fatal { $self->session->output->print('
'.$self->session->setting->get("companyURL"),1); } $self->session->close(); - die "fatal: " . $message; + last WEBGUI_FATAL; } @@ -282,6 +285,7 @@ The message you wish to add to the log. sub info { my $self = shift; my $message = shift; + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $self->getLogger->info($message); $self->{_debug_info} .= $message."\n"; } @@ -301,7 +305,6 @@ An active WebGUI::Session object. sub new { my $class = shift; my $session = shift; - $Log::Log4perl::caller_depth=1; Log::Log4perl->init_once( $session->config->getWebguiRoot."/etc/log.conf" ); my $logger = Log::Log4perl->get_logger($session->config->getFilename); bless {_queryCount=>0, _logger=>$logger, _session=>$session}, $class; @@ -326,12 +329,16 @@ sub query { $self->{_queryCount}++; my $plac; if (defined $placeholders and ref $placeholders eq "ARRAY" && scalar(@{$placeholders})) { - $plac = "\n  with placeholders:  ['".join("', '",@{$placeholders})."']"; + $plac = "\n with placeholders: [" . join(', ', map { + defined $_ ? "'$_'" : 'undef'; + } @$placeholders) . ']'; } else { $plac = ''; } - $self->debug("query ".$self->{_queryCount}.': '.$query.$plac); + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; + $query =~ s/^/ /gms; + $self->debug("query ".$self->{_queryCount}.":\n" . $query . $plac); } @@ -380,31 +387,28 @@ errors, sql queries and form data. sub showDebug { my $self = shift; - my $text = $self->{_debug_error}; - $text =~ s/\n/\
\n/g; - my $output = '
'.$text."
\n"; + my $output = '
'; + my $text = $self->{_debug_error}; + $text = encode_entities($text); + $output .= '
'.$text."
"; $text = $self->{_debug_warn}; - $text =~ s/\n/\
\n/g; - $output .= '
'.$text."
\n"; + $text = encode_entities($text); + $output .= '
'.$text."
"; $text = $self->{_debug_info}; - $text =~ s/\n/\
\n/g; - $output .= '
'.$text."
\n"; - my $form = $self->session->form->paramsHashRef(); - foreach my $key (keys %{$form}) { - if ($key eq "password" || $key eq "identifier") { - $form->{$key} = "********"; - } - } - $text = JSON->new->utf8->pretty->encode($form); - $text =~ s/&/&/sg; - $text =~ s/>/>/sg; - $text =~ s/\n/g; - $text =~ s/ /    /g; - $output .= '
'.$text."
\n"; + $text = encode_entities($text); + $output .= '
'.$text."
"; + my %form = %{ $self->session->form->paramsHashRef }; + $form{password} = "*******" + if exists $form{password}; + $form{identifier} = "*******" + if exists $form{identifier}; + $text = JSON->new->utf8->pretty->encode(\%form); + $text = encode_entities($text); + $output .= '
'.$text."
"; $text = $self->{_debug_debug}; - $text =~ s/\n/\
\n/g; - $output .= '
'.$text."
\n"; + $text = encode_entities($text); + $output .= '
'.$text."
"; + $output .= '
'; return $output; } @@ -425,6 +429,7 @@ The message you wish to add to the log. sub warn { my $self = shift; my $message = shift; + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $self->getLogger->warn($message); $self->{_debug_warn} .= $message."\n"; } diff --git a/lib/WebGUI/URL/Content.pm b/lib/WebGUI/URL/Content.pm index fc0651612..75fba546c 100644 --- a/lib/WebGUI/URL/Content.pm +++ b/lib/WebGUI/URL/Content.pm @@ -52,7 +52,7 @@ sub handler { my ($request, $server, $config) = @_; $request->push_handlers(PerlResponseHandler => sub { my $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server); - foreach my $handler (@{$config->get("contentHandlers")}) { + WEBGUI_FATAL: foreach my $handler (@{$config->get("contentHandlers")}) { my $output = eval { WebGUI::Pluggable::run($handler, "handler", [ $session ] )}; if ( my $e = WebGUI::Error->caught ) { $session->errorHandler->error($e->package.":".$e->line." - ".$e->error); @@ -80,12 +80,13 @@ sub handler { elsif ($session->http->getStatus < 200 || $session->http->getStatus > 299) { $session->http->sendHeader; last; - } + } } } $session->close; return Apache2::Const::OK; }); + $request->push_handlers(PerlMapToStorageHandler => sub { return Apache2::Const::OK }); $request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK }); return Apache2::Const::OK; }