From b57a0788c22a8b48cd2d57b40150abd3cb6e3b8f Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Thu, 21 Feb 2019 16:25:02 +0100 Subject: [PATCH] Check JSON structure (#1595) --- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index 3f6713a57..a3609a615 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -15,6 +15,7 @@ package Lemonldap::NG::Portal::Main; use strict; use URI::Escape; +use JSON; # List constants sub authProcess {qw(extractFormInfo getUser authenticate)} @@ -729,17 +730,25 @@ sub sendHtml { $troverJson = $args{templateDir} . "/$template.json"; $self->logger->debug("-> Trying to load $tmpl"); } + if ( -r $troverJson ) { open my $tr_file, '<', $troverJson - or die "Can't open" - . $troverJson . " : $!"; + or die "Can't open" . $troverJson . " : $!"; while (<$tr_file>) { chomp; $args{params}->{TROVERbyJSON} .= $_; } close $tr_file or die "Can't close $tr_file : $!"; - $self->logger->debug(" -> Overriding messages with $troverJson"); - $self->logger->debug(" -> File content : $args{params}->{TROVERbyJSON}"); + eval { decode_json( $args{params}->{TROVERbyJSON} ) }; + if ($@) { + $self->logger->debug("$troverJson is NOT a regular JSON file!!!"); + $args{params}->{TROVERbyJSON} = ''; + } + else { + $self->logger->debug(" -> Overriding messages with $troverJson"); + $self->logger->debug( + " -> File content : $args{params}->{TROVERbyJSON}"); + } } my $res = $self->SUPER::sendHtml( $req, $template, %args ); push @{ $res->[1] },