Skip to content

Commit 2719917

Browse files
authored
Merge pull request sympa-community#833 from ikedas/issue-831 by ikedas
Scenario fails with negative indices in [header->Field][n] (sympa-community#831)
2 parents 07d185d + cc700b9 commit 2719917

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib/Sympa/Scenario.pm

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
99
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
1010
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
11-
# Copyright 2017, 2018 The Sympa Community. See the AUTHORS.md file at the
12-
# top-level directory of this distribution and at
11+
# Copyright 2017, 2018, 2019 The Sympa Community. See the AUTHORS.md file
12+
# at the top-level directory of this distribution and at
1313
# <https://github.com/sympa-community/sympa.git>.
1414
#
1515
# This program is free software; you can redistribute it and/or modify
@@ -583,9 +583,11 @@ sub _compile_scenario {
583583
my $required = join "\n", map {
584584
my $req;
585585
if ($_ eq 'list_object') {
586-
$req = 'return undef unless ref $that eq \'Sympa::List\';';
586+
$req = 'die "No list context" unless ref $that eq \'Sympa::List\';';
587+
} elsif ($_ eq 'message') {
588+
$req = sprintf '$context->{message} ||= Sympa::Message->new("\n");';
587589
} else {
588-
$req = sprintf 'return undef unless exists $context->{%s};', $_;
590+
$req = sprintf 'die "Missing parameter \'%s\'" unless exists $context->{%s};', $_, $_;
589591
}
590592
" $req";
591593
} sort keys %required;
@@ -785,7 +787,7 @@ sub _compile_condition {
785787
## available.
786788
if (defined $index) {
787789
$value =
788-
sprintf '[$context->{message}->get_header(\'%s\')]->[%s]',
790+
sprintf 'do { my @h = $context->{message}->get_header(\'%s\'); $h[%s] }',
789791
$field_name, $index;
790792
} else {
791793
$value = sprintf '[$context->{message}->get_header(\'%s\')]',

0 commit comments

Comments
 (0)